我正在尝试使用Microsoft Office Interop创建Word文档。该文件应包含一张图片和一些表格内容。但是,当我添加内容时,它不会以我需要的方式添加。在C#中创建Word文档#
我已经提供了下面的示例代码。
MSWord.Application oWordApp;
MSWord.Document oWordDoc;
oWordApp = new MSWord.Application();
oWordApp.Visible = true;
oWordApp.WindowState = MSWord.WdWindowState.wdWindowStateMinimize;
oWordDoc = oWordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
object start = 0;
object end = 0;
Microsoft.Office.Interop.Word.Range oRange = oWordDoc.Range(ref start,ref end);
oWordDoc.InlineShapes.AddPicture(imagepath, ref oMissing, ref oMissing, oRange);
Microsoft.Office.Interop.Word.Table tbl = oWordDoc.Tables.Add(oRange, 10, 2, ref oMissing, ref oMissing);
Random rnd = new Random();
for (int i = 0; i < 10; i++)
{
tbl.Rows[i + 1].Cells[1].Range.Text = "Item#";
tbl.Rows[i + 1].Cells[2].Range.Text = "Sample";
}
oWordDoc.SaveAs(svd.FileName, 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, ref oMissing, ref oMissing);
什么做的代码输出? – Raptor
你期望什么? – anothershrubery
问题是什么? – Slugart