Update word to newest format with open xml - c#

I have an application that download docx file from a service.
The problem is that the service creates the docx with the an old format (I think it used the open xml version 2.0).
I don't own the service so I can't change the creation process of the word , but I thought about building a convertor , that will open the downloaded files and recreate them in the newest format using the open xml sdk version 2.5.
I was optimistic when I thought this code will work ( A simple open and save) :
WordprocessingDocument wordprocessingDocument =
WordprocessingDocument.Open(filePath, true);
wordprocessingDocument.MainDocumentPart.Document.Save();
I'm not fimiliar with the open xml sdk , so any help will be appreciated.

You're just opening the doc and saving it with no changes. You need to change the Word version, then save it. This article should provide the info you need: http://blogs.msmvps.com/wordmeister/2013/01/18/openxmlsdk-word-compatibility-mode/

Related

FlexCel created corrupted xlsx file

I use the FlexCel library to create an Excel report in the .xlsx format.
When creating a file in .xls format - everything works fine.
When I try to create a file in the .xlsx format, the file is created, but when I open it by Excel, I get an error that the file is corrupt and can not be opened. And the file has the size in half from .xls.
If someone has encountered a similar problem or knows a solution, I will be very grateful for the answer.
Edit:
My code
var templateFilePath = "D:/template.xlsx";
var newReportPath = "D:/report.xlsx";
using (var fr = new FlexCelReport(true))
{
fr.AddTable("SOReport", dataTable);
fr.Run(
templateFilePath,
newReportPath
);
}
I had the same problem with export in xlsx format with old versions of FlexCel.
Currently I've tested it on FlexCel v5.5.1.0 and there is interesting behaviour:
If I use Excel 2016 or above to create xlsx templates - then I get "file is corrupted" error while trying to open exported xlsx file.
But if I use Excel 2013 or below to create xlsx templates - then I can open it perfectly without errors.
Also mention that if you open xlsx template created by Excel 2013 or below in Excel 2016 or above and save it - you can't restore it to working state in the future. Template will lost for you.
Too late but I hope this can help you.
P.S. Probably, FlexCel team (TMS Software) fixed it starting with v6.7.16.0 version of FlexCel. I think so because documentation said something similar: https://www.tmssoftware.com/site/flexcelnet.asp?s=history
Points like Improved : Improved compatibility with invalid xls and xlsx files
But I can't argue that.

Emending PDF files into OpenXML WordprocessingML

I am strugling with Open XML SDK and embedding pdf files into a docx file.
I do not want to use automation
I am able to create *.bin files from everything except from *.pdf (see this question)
Anyone has experience with this? From what I've gathered you must create a *.bin file in order to embedd any file into Word *.docx document (except images). Is that correct?
If you can't find a pure C# solution, you could consider the commercial product docx4j OLE Helper IKVM'd.
Disclosure: I wrote it.
The reason for pdf not working was in fact in acrobat reader.
When Ive installed older version (or did not have AR installed at all), it started to work.

compare openxml files

I'm developping a tool to manage some documents with versioncontrol. I have a windows client who is comparing 2 documents (previous version with current version) to see the differences between both documents. That is working fine (i'm using the interop dll's of microsoft).
I also have a web client where i want to do the same thing, but i don't want to install office on the server.
In my web client i only alow openxml files (docx, xlsx) because i can read and update versiondate in the document without having office installed.
Is there some tool where i can compare 2 openxml files with and show differences in a new document? (i already searched on it and there is some tool openxmldiff, but the results i get are some xml files and don't know how to combine them in a new document.
Any help?
You may want to take a look at OpenXml Powertools:
http://powertools.codeplex.com/
It has a DocumentComparer Class.
At least it is maybe a starting point.
The Open XML SDK 2.0 Productivity tool has a compare files option that will diff the two open xml files and show you the differences.

Opening Dot File with OpenXML

I need to work on opening a DOT (word document template) file, replace the fillers and save it as Document file.
On opening DOT file I am getting "Document File is Corrupted".
Is it possible to work with DOT file using OpenXML.
UPDATE: I am saving DOT file as XML (manually using "Save as.."). Renaming file back to dot, so it is XML file built on WordML. Still trying to open it through OpenXML giving me the same error.
OpenXML is used in the new formats of Office 2007 (.dotx and .docx).
WordML is a bit older and cannot be used with the OpenXML libraries.
You can load a WordML file as an XmlDocument or load it into a string if you know exactly what data you want to replace.

Open XML SDK 2.0 inserting PDF to Word

has anyone tried to insert pdf document into word using open xml sdk 2.0 ?
Thank You!
With the SDK there is a tool called DocumentReflector (in folder C:\Program Files\Open XML Format SDK\V2.0\tools). This tool opens an existing OpenXML document and generates the code that will produce this document.
Now you can create a simple document in Word with an embedded PDF and open this document using DocumentReflector. The code generated can then be a base for your document creation process.

Categories