Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with Open XML SDK #1700

Open
cjalex1313 opened this issue Mar 26, 2024 · 0 comments
Open

Bug with Open XML SDK #1700

cjalex1313 opened this issue Mar 26, 2024 · 0 comments

Comments

@cjalex1313
Copy link

Describe the bug
Docx file generated with OpenXML isn't able to be exported by soffice in linux (has something to do with the content)

To Reproduce
// code snippet
using (MemoryStream memoryStream = new MemoryStream())
{
using (var doc = DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Create(memoryStream, DocumentFormat.OpenXml.WordprocessingDocumentType.Document, true))
{
MainDocumentPart mainPart = doc.AddMainDocumentPart();
mainPart.Document = new Document();
Body body = mainPart.Document.AppendChild(new Body());
var table = new Table();
TableProperties tableProperties = new TableProperties();
tableProperties.TableWidth = new TableWidth() { Width = "5000", Type = TableWidthUnitValues.Pct };
table.AppendChild(tableProperties);
TableGrid tableGrid = new TableGrid(
new GridColumn(),
new GridColumn()
);
table.AppendChild(tableGrid);
TableRow tableRow = new TableRow();
TableCell tc1 = new TableCell(
new TableCellProperties(new TableCellWidth() { Width = "2500", Type = TableWidthUnitValues.Pct }),
new Paragraph(new Run(
new RunProperties(new FontSize() { Val = "56" }, new RunFonts() { Ascii = "Times New Roman" }),
new Text("Patient Hours Detail")
)
)
);
TableCell tc2 = new TableCell(
new TableCellProperties(new TableCellWidth() { Width = "2500", Type = TableWidthUnitValues.Pct }),
new Paragraph(new ParagraphProperties(new Justification() { Val = JustificationValues.Right }), new Run(new RunProperties(new FontSize() { Val = "34" }, new RunFonts() { Ascii = "Times New Roman" }), new Text(model.CaseName))),
new Paragraph(new ParagraphProperties(new Justification() { Val = JustificationValues.Right }), new Run(new RunProperties(new FontSize() { Val = "26" }, new RunFonts() { Ascii = "Times New Roman" }), new Text($"{model.StartDate.ToString("MM/dd/yyyy")} through {model.EndDate.ToString("MM/dd/yyyy")}")))
);
tableRow.Append(tc1);
tableRow.Append(tc2);
table.AppendChild(tableRow);
body.Append(table);
doc.Save();
memoryStream.Position = 0;
var byteArray = memoryStream.ToArray();
return byteArray;

then save the byteArray as "sdfomsef.docx" locally

then soffice --headless --convert-to pdf sdfomsef.docx

Error: source file could not be loaded

Expected behavior
If I try remove the 2nd table cell this works (this line tableRow.Append(tc2);)

Desktop (please complete the following information):

  • OS: Docker mcr.microsoft.com/dotnet/aspnet:6.0
  • Office version [e.g. 16.0.15427.20178]
  • .NET Target: .net6
  • DocumentFormat.OpenXml Version: 3.0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant