c# – 将两个表直接添加到word文档中
发布时间:2020-12-15 21:31:39 所属栏目:百科 来源:网络整理
导读:Word具有此功能,它合并插入在一起的表,因此要添加两个单独的表,您必须在它们之间放置一个段落.这一直运作良好,但现在我需要在将表格分开后使段落消失,以便它们彼此叠加. var document = GetDocument(word,@"C:Blank.docx");object missing = System.Reflect
Word具有此功能,它合并插入在一起的表,因此要添加两个单独的表,您必须在它们之间放置一个段落.这一直运作良好,但现在我需要在将表格分开后使段落消失,以便它们彼此叠加.
var document = GetDocument(word,@"C:Blank.docx"); object missing = System.Reflection.Missing.Value; var paragraph = document.Paragraphs.Add(ref missing); paragraph.Range.Text = "..."; var table = document.Tables.Add(paragraph.Range,1,ref missing,ref missing); table.Borders.Enable = 1; paragraph.Range.Collapse(Microsoft.Office.Interop.Word.WdCollapseDirection.wdCollapseEnd); paragraph.Range.InsertParagraphAfter(); paragraph.Range.Collapse(Microsoft.Office.Interop.Word.WdCollapseDirection.wdCollapseEnd); paragraph = document.Paragraphs.Add(ref missing); paragraph.Range.Text = "..."; table = document.Tables.Add(paragraph.Range,ref missing); table.Borders.Enable = 1; document.Save(); var doc_close = (Microsoft.Office.Interop.Word._Document)document; doc_close.Close(); Marshal.ReleaseComObject(document); 上图显示了上述代码的结果.我想删除两个表之间的段落,但不知道如何使用com对象.需要注意的一件重要事情是,要删除单词中的段落,您必须按“删除”而不是“退格”.我认为这是找到正确答案的重要提示. 这个例子让我觉得我想做一些可以用单个表完成的事情,但实际的应用程序工作方式不同,需要两个不同的表堆叠在一起. 解决方法
我会尝试使用这个Lib
http://docx.codeplex.com/我发现它回来看起来比com更容易使用
您也可以随时使用openxml SDK for office,但我怀疑docx会更容易 http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=5124 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |