private void ImportWordFile() { ImportLog.Clear(); String filename = WordFilePath.Text; if (string.IsNullOrWhiteSpace(filename)) { MessageBox.Show("请先选择导入文件"); return; } //载入Word文档 Document document = new Document(filename); Section section = document.Sections[0]; int i = 1; foreach (Spire.Doc.Table table in section.Tables) { ImportLog.AppendText("导入表格" + i + ",自动查找匹配模式开始...\r\n"); string[] cls = getDocColumsFromDocTable(table); int matchindex = getMatchIndex(cls); if (matchindex < 0) { ImportLog.AppendText("查找匹配模式失败,请添加合适的匹配模式\r\n"); } else { ImportLog.AppendText("查找匹配模式成功,匹配模式为:" + MatchListBox.Items[matchindex].ToString() + "\r\n"); ImportTableData(matchindex, table); } i++; } //Spire.Doc.Table table = section.Tables[0] as Spire.Doc.Table; ////实例化StringBuilder类 //StringBuilder sb = new StringBuilder(); ////遍历表格中的段落并提取文本 //foreach (TableRow row in table.Rows) //{ // foreach (TableCell cell in row.Cells) // { // foreach (Paragraph paragraph in cell.Paragraphs) // { // sb.AppendLine(paragraph.Text); // } // } //} //ImportLog.Text = sb.ToString(); }