寻找一种以编程方式将注释(使用Word中的注释功能)插入MS Word文档中的特定位置的方法.我更喜欢一种可用于最新版本的MS Word标准格式并可在非Windows环境中实现的方法(理想情况下使用Python和/或Common Lisp).我一直在看OpenXML SDK,但似乎无法在那里找到解决方案.
我有一些代码将打开Word 2007(docx)文档并更新相应的CustomXmlPart(因此,当它们映射到CustomXmlPart时更新文档本身的内容控件)但无法解决如何将其保存为一个新文件.当然不会那么难!
我目前的想法是,我需要打开模板并将内容复制到一个新的空白文档中 - 逐个文件,在遇到它时更新CustomXmlPart.叫我老式,但听起来有点笨重!
为什么我不能只做一个WordprocessingDocument.SaveAs(filename); ...?
请告诉我,我在这里缺少一些简单的东西.
提前致谢
我正在使用内容控件和OpenXML SDK实现ms word文档生成.我想对该代码进行一些自动化测试(单元测试或一些简单的UI自动化测试).
有没有人有测试MS Word文档生成的经验?有哪些可能的选择?
提前致谢!
是否有开发工具包/ lib(用c或c ++编写)来编写docx文件?微软有一个开发工具包,但它是用C#编写的.
所以!:)简单的问题 - 它可能被问到,但我找不到它.我正在使用Open XML SDK和C#从XLSX检索数据.我想获得"第一张"表(就像你在Excel中看到的第一张),但是当我使用时......
WorkbookPart wbPart = workBook.WorkbookPart;
//Now let's find the dimension of the first worksheet
string sheetArea = wbPart.WorksheetParts.First().Worksheet.SheetDimension.Reference.Value;
Run Code Online (Sandbox Code Playgroud)
不幸的是,在一个全新的XLSX中,这拉动了"Sheet3"而不是"Sheet1".我提前不知道工作表名称,也不能强制用户只提交一张工作簿或指定工作表名称.我目前的要求是抓住第一张纸.
有人可以帮忙吗?:)
编辑:我想通了!但我无法回答7个小时的问题,所以......
我通过挖掘其他SO问题的答案找到了这个:
Open XML SDK 2.0 - 如何更新电子表格中的单元格?
从本质上讲,一个工作的例子可能是这样的:
(wbPart.GetPartById(wbPart.Workbook.Sheets.Elements<Sheet>().First().Id.Value) as WorksheetPart).Worksheet.SheetDimension.Reference.Value
Run Code Online (Sandbox Code Playgroud) 使用SDK我正在构建包含报告的Word文档.这些文件需要有TOC.有没有人有一个完整的解决方案,我可以遵循,以了解如何做到这一点?
(我已经阅读了http://openxmldeveloper.org/上的所有内容)
我正在编写一个.NET应用程序,它应该读取200页长的.docx文件(通过DocumentFormat.OpenXML 2.5)来查找文档应该包含的某些标记的所有出现.为了清楚起见,我不是在寻找OpenXML标签,而是寻找应该由文档编写者设置到文档中的标签,作为我需要在第二阶段填写的值的占位符.此类标签应采用以下格式:
<!TAG!>
Run Code Online (Sandbox Code Playgroud)
(其中TAG可以是任意字符序列).正如我所说,我必须找到所有这些标签的出现加上(如果可能的话)找到已找到标签出现的"页面".我在Web上发现了一些东西,但不止一次基本方法是将文件的所有内容转储到字符串中,然后查看这样的字符串,无论.docx编码如何.这或者导致误报或者根本没有匹配(虽然测试.docx文件包含多个标签),其他示例可能与我对OpenXML的了解有点差异.找到这样的标签的正则表达式模式应该是这样的:
<!(.)*?!>
Run Code Online (Sandbox Code Playgroud)
标签可以在整个文档中找到(在表格,文本,段落内,也可以在页眉和页脚中).
我在Visual Studio 2013 .NET 4.5中进行编码,但如果需要,我可以回来.PS我更喜欢不使用Office Interop API的代码,因为目标平台不会运行Office.
我可以生成的最小.docx示例存储此内部文档
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 wp14">
<w:body>
<w:p w:rsidR="00CA7780" w:rsidRDefault="00815E5D">
<w:pPr>
<w:rPr>
<w:lang w:val="en-GB"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:lang w:val="en-GB"/>
</w:rPr>
<w:t>TRY</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00815E5D" w:rsidRDefault="00815E5D">
<w:pPr>
<w:rPr>
<w:lang w:val="en-GB"/>
</w:rPr>
</w:pPr>
<w:proofErr w:type="gramStart"/>
<w:r>
<w:rPr>
<w:lang w:val="en-GB"/>
</w:rPr>
<w:t><!TAG1</w:t>
</w:r>
<w:proofErr w:type="gramEnd"/>
<w:r>
<w:rPr>
<w:lang w:val="en-GB"/> …Run Code Online (Sandbox Code Playgroud) 我有一个基本的C#应用程序,其中使用了Open XML SDK.我想让它在我的Nginx和Ubuntu和DigitalOcean服务器上运行.
该应用程序在Windows中编译并运行良好,而我的Mac在单声道中运行良好.然后,我在Ubuntu服务器上安装了mono,并将.exe文件scp到服务器,然后运行mono ConsoleApplication2.exe,它返回了以下错误:
Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
File name: 'DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
at ConsoleApplication2.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
File name: 'DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
at ConsoleApplication2.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
Run Code Online (Sandbox Code Playgroud)
我找到了这个链接,似乎问题来自于版本DocumentFormat.OpenXml.但是我怎么能在Ubuntu服务器上安装正确的版本呢? …
编辑:此问题的文本已更改为反映利用开放的xml代码和互操作.
我试图通过功能区将基本64位编码的图像插入Word文档.以下代码用于复制目的:
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void InsertPicture_Click(object sender, RibbonControlEventArgs e)
{
Word.Application wordApp = null;
Word.Document currentDocument = null;
Word.ContentControls controls = null;
try
{
wordApp = (Word.Application) Marshal.GetActiveObject("Word.Application");
currentDocument = wordApp.ActiveDocument;
controls = currentDocument.ContentControls;
currentDocument.Range().InsertXML(@"<pkg:package xmlns:pkg=""http://schemas.microsoft.com/office/2006/xmlPackage"">
<pkg:part pkg:name=""/word/media/image1.png"" pkg:contentType=""image/png"" pkg:compression=""store"">
<pkg:binaryData>iVBORw0KGgoAAAANSUhEUgAAABEAAAAKCAIA
AADdHiL1AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAVSURBVChTY3gro0IqGtUz3PTIqAAAlO/H4+qBWxcAAAAASUVORK5CYII=</pkg:binaryData>
</pkg:part></pkg:package>");
object tr = true;
object fa = false;
}
catch(Exception ex)
{
wordApp.ActiveDocument.Range().InsertAfter(ex.Message);
}
finally
{
if (controls != null) Marshal.ReleaseComObject(controls); controls = null;
if …Run Code Online (Sandbox Code Playgroud)