C#读取Word表格中数据的完整代码
2010-07-06 14:20
429 查看
public void readWordFile()
{
object oFileName = @"../Files/Employees0.doc";
object oReadOnly = true;
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word._Application oWord = new
Microsoft.Office.Interop.Word.Application();
oWord.Visible = true;
Microsoft.Office.Interop.Word._Document oDoc = oWord.Documents.Open(ref oFileName, ref
oMissing, ref oReadOnly, ref oMissing, ref oMissing,ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing,ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing);
for (int tablePos = 1; tablePos <= oDoc.Tables.Count; tablePos++)
{
Microsoft.Office.Interop.Word.Table nowTable = oDoc.Tables[tablePos];
string tableMessage = string.Format("第{0}/{1}个表:/n", tablePos, oDoc.Tables.Count);
for (int rowPos = 1; rowPos <= nowTable.Rows.Count; rowPos++)
{
for (int columPos = 1; columPos <= nowTable.Columns.Count; columPos++)
{
tableMessage += nowTable.Cell(rowPos, columPos).Range.Text;
tableMessage += tableMessage.Remove(tableMessage.Length - 2, 2);
tableMessage += "/t";
}
tableMessage += "/n";
}
string msgTable = tableMessage;
}
oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
Marshal.ReleaseComObject(oDoc);
Marshal.FinalReleaseComObject(oWord);
oWord = null;
}
{
object oFileName = @"../Files/Employees0.doc";
object oReadOnly = true;
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word._Application oWord = new
Microsoft.Office.Interop.Word.Application();
oWord.Visible = true;
Microsoft.Office.Interop.Word._Document oDoc = oWord.Documents.Open(ref oFileName, ref
oMissing, ref oReadOnly, ref oMissing, ref oMissing,ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing,ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing);
for (int tablePos = 1; tablePos <= oDoc.Tables.Count; tablePos++)
{
Microsoft.Office.Interop.Word.Table nowTable = oDoc.Tables[tablePos];
string tableMessage = string.Format("第{0}/{1}个表:/n", tablePos, oDoc.Tables.Count);
for (int rowPos = 1; rowPos <= nowTable.Rows.Count; rowPos++)
{
for (int columPos = 1; columPos <= nowTable.Columns.Count; columPos++)
{
tableMessage += nowTable.Cell(rowPos, columPos).Range.Text;
tableMessage += tableMessage.Remove(tableMessage.Length - 2, 2);
tableMessage += "/t";
}
tableMessage += "/n";
}
string msgTable = tableMessage;
}
oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
Marshal.ReleaseComObject(oDoc);
Marshal.FinalReleaseComObject(oWord);
oWord = null;
}
相关文章推荐
- C#读取Word表格中的数据
- [原]C# 读取Word 表格数据(单元格纵合并)
- C#调用NPOI组件读取excel表格数据转为datatable写入word表格中并向word中插入图片/文字/书签 获得书签列表
- 使用C#读取Word表格数据
- C#读取Word表格中的数据 (转)
- C#读取Word表格中的数据
- C# 读取Word 表格数据(单元格纵合并)
- 【20090313-01】C#读取Word表格中的数据 (转)
- C#读取Word表格数据
- C#读取Word表格中的数据 (转)
- C#调用NPOI组件读取excel表格数据转为datatable写入word表格中并向word中插入图片/文字/书签 获得书签列表
- C#读取Word表格中的数据 (转)
- C#实现Word中表格信息读取
- 用java的poi类读取一个excel表格的内容后再写入到一个新excel表格中的完整代码
- C#实现Word中表格信息读取
- C#.NET示例读写xml所有节点的代码实现方法和读取xml节点的数据总结
- jquery 读取页面表格中的数据 生成批量insert代码 并以ajax方式传给后台
- 用C#动态生成Word文档并将数据填入Word表格中
- C#实现Word中表格信息读取
- 用C#实现动态生成Word文档,在Word文档中插入表格,并将读出的数据填入到表格中