对不起,如果这是一个补救问题,我确实在发布之前到处都找不到答案。
我有一个简单的 C# 应用程序,它打开一个 MS Word 文档,查看 3 列,然后插入数据库。这部分工作正常。
我的问题是:在某些文档中,某些文本带有删除线。我想把它去掉。我看了一遍,很明显我错过了一些东西。
具体来说,有问题的列是名为Graphicstext
. 我只需要为此删除删除线,我已经尝试了一些东西,但我真的不知道该怎么做。先感谢您。
foreach(Table tb in docs.Tables) {
//for (int row = 1; row <= tb.Rows.Count; row++)
int ColumnCount = tb.Columns.Count;
for (int row = 1; row <= tb.Rows.Count; row++) {
PageCell = tb.Cell(row, 1);
EnglishTextCell = tb.Cell(row, 2);
TranslationsCell = tb.Cell(row, 3);
GlossaryCell = tb.Cell(row, 4);
//GraphicsCell = tb.Cell(row, 5);
GraphicsCell = tb.Cell(row, ColumnCount);
string Pagetext = PageCell.Range.Text;
Pagetext = stripCellText(Pagetext);
string Englishtext = EnglishTextCell.Range.Text.ToString();
Englishtext = NewLineCellText(Englishtext);
string Translationtext = TranslationsCell.Range.Text.ToString();
Translationtext = stripCellText(Translationtext);
string Glossarytext = GlossaryCell.Range.Text.ToString();
Glossarytext = stripCellText(Glossarytext);
string Graphicstext = GraphicsCell.Range.Text.ToString();
Graphicstext = stripCellText(Graphicstext);
string filenametouse = System.IO.Path.GetFileNameWithoutExtension(filePath);
string file1 = filenametouse.Substring(0, 3);
string file2 = filenametouse.Substring(3, 2);
string file3 = file1 + "-" + file2;
//MessageBox.Show("row should be: " + Pagetext + " " + Englishtext + " " + Translationtext + " " + Glossarytext + " " + Graphicstext);
//wfile.WriteLine("row should be: " + Pagetext + "|" + Englishtext + "|" + Translationtext + "|" + Glossarytext + "|" + Graphicstext );
wfile.WriteLine("row should be: " + file3 + "|" + Pagetext + "|" + Englishtext + "|" + Graphicstext);
wfile.WriteLine("");
string cmdText = "INSERT INTO Lesson_Info(LessonName,PageNumber,EnglishText,Graphics)VALUES(@lesson,@pagetext,@Englishtext,@Graphicstext)";
System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand(cmdText, conn);
cmd.Parameters.AddWithValue("@lesson", file3);
cmd.Parameters.AddWithValue("@pagetext", Pagetext);
cmd.Parameters.AddWithValue("@Englishtext", Englishtext);
cmd.Parameters.AddWithValue("@Graphicstext", Graphicstext);
cmd.ExecuteNonQuery();
//wfile.WriteLine("row should be: " + Pagetext);
}
}
public string stripCellText(string text) {
return text.Replace("\r\a", "");
//return text.Replace("\n", "");
}