我想在表格单元格中使用OpenXML应用文本对齐方式.
我不明白为什么它没有应用.
Table table = new Table();
TableRow tableHeader = new TableRow();
table.AppendChild<TableRow>(tableHeader);
TableCell tableCell = new TableCell();
tableHeader.AppendChild<TableCell>(tableCell);
Paragraph paragraph = new Paragraph(new Run(new Text("test")));
ParagraphProperties paragraphProperties = new ParagraphProperties();
JustificationValues? justification = GetJustificationFromString("centre");
if (justification != null)
{
paragraphProperties.AppendChild<Justification>(new Justification() { Val = justification });
}
paragraph.AppendChild<ParagraphProperties>(paragraphProperties);
tableCell.AppendChild<Paragraph>(paragraph);
public static JustificationValues? GetJustificationFromString(string alignment)
{
switch(alignment)
{
case "centre" : return JustificationValues.Center;
case "droite" : return JustificationValues.Right;
case "gauche" : return JustificationValues.Left;
default: return null;
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
我有一个xml,我需要使用openxml或nodes()进行解析.xml包含少量使用不同值重复的子标记,如下所示.
<root>
<value>10</value>
<value>12</value>
<value>11</value>
<value>1</value>
<value>15</value>
<root>
Run Code Online (Sandbox Code Playgroud)
对于我的代码,非常重要的是我以与xml中相同的顺序返回所有这些行.我用谷歌搜索和gogled但没有告诉我@mp:id是否总是以与xml中相同的顺序返回.或者,如果nodes()以与遇到它们相同的顺序返回值.
所有我想知道的是我是否可以信任这两种方法中的任何一种并且对行的正确顺序感到满意.
PS原谅上述文本中的任何错误或错误,我也不喜欢在Android窗口中输入代码.
我有一段文字,我想在文件的中心出现.我怎么能在docx4j中这样做?我目前正在使用:
PPr paragraphProperties = factory.createPPr();
//creating the alignment
TextAlignment align = new TextAlignment();
align.setVal("center");
paragraphProperties.setTextAlignment(align);
//centering the paragraph
paragraph.setPPr(paragraphProperties);
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
我 Nugot SpreadsheetLight。为了随后使用它,我需要添加以下用途:
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Spreadsheet;
using SpreadsheetLight;
Run Code Online (Sandbox Code Playgroud)
为了识别前两个(“DocumentFormat”),我还需要使用 NuGet Microsoft 的“Open XML Format SDK”
我得到了最新版本,2.5
然而,即便如此,我还是收到了一个关于需要引用它的错误消息:
“DocumentFormat.OpenXml.Spreadsheet.InlineString”类型是在未引用的程序集中定义的。您必须添加对程序集“DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”的引用。
这行 SpreadsheetLight 代码激起了那个味精:
sl.SetCellValue("A1", true); // "sl" is an SLDocument
Run Code Online (Sandbox Code Playgroud)
因此,我从我的项目中删除了我拥有 NuGot(版本 2.6.0.0,运行时版本 v4.0.30319)的引用,然后通过浏览到 C:\Program Files(x86)\Open XML SDK\V2 添加回引用。 0\lib 并选择“DocumentFormat.OpenXml.dll”
然后我得到了一个编译器警告:
发现同一依赖程序集的不同版本之间存在冲突。请在项目文件中将“AutoGenerateBindingRedirects”属性设置为 true。有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=294190。
我注意到我从文件系统中添加的 DLL 是 2.5.5631.0 版本,而被 NuGot 安装作为参考的那个 DLL 是 2.6.0.0 版本,运行时版本也不同(v4.0.30319 是由NuGetting“Open XML Format SDK”,但是我手动添加的DLL版本是2.5.5631.0,Runtime Version v4.0.30319
根据这个,我得知我应该改变编辑的.csproj文件<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>为真-但AutoGenerateBindingRedirects不存在那里。
我不知道我是否应该添加它,如果是(在哪个“块”中)。我更喜欢谨慎行事并减轻警告引擎的影响。如何确保 OpenXml 程序集不会引起冲突?
I am using Office Open XML and I have to add images at a specific points. On the document I have a \'tag\' so I can locate it just fine. However, when I add more than one image, it corrupts the file.
\n\n\n\nHere\'s my code: (Modified from https://msdn.microsoft.com/en-us/library/office/bb497430.aspx)
\n\nUsing:
\n\nusing DocumentFormat.OpenXml.Wordprocessing;\nusing A = DocumentFormat.OpenXml.Drawing;\nusing DW = DocumentFormat.OpenXml.Drawing.Wordprocessing;\nusing PIC = DocumentFormat.OpenXml.Drawing.Pictures;\nRun Code Online (Sandbox Code Playgroud)\n\nMy Main:
\n\nprivate const string Loc = @"D:\\Documents\\2-Mass Output.docx";\nstatic void Main(string[] args)\n{\n var …Run Code Online (Sandbox Code Playgroud) 我有一个 Excel 表,我将其用作导出数据的模板文件。
Excel 工作表是 XLSM 文件,几乎没有用 VBA 编写的代码。
每次使用时间戳复制和重命名文件时,都应将数据写入复制的 xlsm 文件,但不写入数据。
我为此使用了 Open XML 库。
如果我使用 xlsx 模板文件,同样有效。
是否无法通过 Open XML 在启用了宏的 xlsm Excel 上写入?
如果是,请记住任何说明。
我通常会使用 ClosedXML 来生成 Excel 文件。核心项目迫使我只使用 OpenXML。
将下载生成的 Excel 文件。
我遇到了一个问题,其中提供给 SpreadsheetDocument 的内存流为空。
我尝试了多种方法来生成流。下面的代码代表了一个精简版,只创建了最基本的东西。同样,内存流是0有长度的。
我知道我应该使用using()等。这只是精简代码以尝试让它工作。
生成excel的代码;这是来自File对象的构造函数。AsMemoryStream是一个属性声明为public MemoryStream AsMemoryStream { get; private set; }
public File(IList<T> items)
{
if (!items.Any())
throw new InvalidOperationException("items cannot be empty");
MemoryStream documentStream = new MemoryStream();
SpreadsheetDocument document = SpreadsheetDocument.Create(documentStream, DocumentFormat.OpenXml.SpreadsheetDocumentType.Workbook);
WorkbookPart workbookPart = document.AddWorkbookPart();
workbookPart.Workbook = new Workbook();
WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet();
Sheets sheets = workbookPart.Workbook.AppendChild(new Sheets());
Sheet sheet = new Sheet { …Run Code Online (Sandbox Code Playgroud) 对不起我的英语:)
\n\n有一个代码
\n\nusing (var sourceDoc = PresentationDocument.Open(@"d:\\source.pptx", false))\n{\n using (var destDoc = PresentationDocument.Open(@"d:\\dest.pptx", true))\n {\n\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我尝试从位置 4 复制幻灯片 \xe2\x84\x962sourceDoc并粘贴到destDoc位置 4。
有同标题的文章“将幻灯片从一个演示文稿复制到另一个演示文稿”和“如何组装多个 PowerPoint 幻灯片”,但不幸的是我无法应用它。我只是很困惑。例如:
\n\nuniqueId = GetMaxIdFromChild(destPresPart.Presentation.SlideMasterIdList);\nRun Code Online (Sandbox Code Playgroud)\n\n这是什么意思?编译时说错误。
\n\n我创建了将幻灯片复制到另一个演示文稿的方法
\n\n/// <summary>\n/// Copy one slide to another presentation\n/// </summary>\n/// <param name="sourcePresentationPath"></param>\n/// <param name="slidePosition">\n/// Slide number from source presentation which will be copy to destinition presentation\n/// </param>\n/// <param name="destPresentationPath"></param>\n/// <remarks>Slide copy to …Run Code Online (Sandbox Code Playgroud) 我有一个受密码保护的 Excel 文件。我正在使用 OpenXml 来读取 Excel 文件。
如下面的代码片段所示,没有重载/可选参数来指定密码。
_document = SpreadsheetDocument.Open(_stream, false);
Run Code Online (Sandbox Code Playgroud)
我没有看到任何读取受密码保护的文件的规定。
有没有办法使用 OpenXml 读取 C# 中受密码保护的 Excel 文件。
谢谢!
我使用 C# OpenXML 生成了一个包含数据和基于数据的图表的电子表格。
我现在想把这个图表嵌入到一个 word 文档中,这样当这些报告发出时,如果需要,可以编辑图表(不是外部链接)。
我已经环顾了几个小时,但找不到任何一致的文档来实现这一目标。大多数潜在客户似乎都在谈论“EmbeddedPackageParts”。
如果有人有任何有用的文章或可以提供一些清晰度,将不胜感激。
干杯,邓肯。
openxml ×10
c# ×7
openxml-sdk ×5
excel ×4
alignment ×1
asp.net-core ×1
csproj ×1
docx4j ×1
ms-office ×1
ms-word ×1
nuget ×1
powerpoint ×1
sql ×1
sql-server ×1
vba ×1