Eric White
Forum Replies Created
-
AuthorPosts
-
The problem here is that you need PresentationBuilder, which can neatly remove a slide from a presentation, but PresentationBuilder is written in C# using the Open-Xml-Sdk, and you need JavaScript.
The best approach –
- Take a copy of the presentation before you have deleted the slide you want to remove
- Take another copy, open in PowerPoint, delete the slide, save
- Use the Open XML SDK Productivity Tool to compare the two, and make detailed notes on all the changes you need to make.
- Write your code to make the same changes. Validate your code by comparing with the second copy in the above procedure.
Are you using the Open-Xml-Sdk for JavaScript?
Cheers, Eric
This is awesome. BTW, if you are git savvy, and want to create a pull request for the Open-Xml-Sdk, I would welcome that.
Hi,
The WmlDocument is an abstraction for an unopened Open XML document. It is a thin wrapper over a byte array. If you want to process a document successively by the Open-Xml-Sdk, and then by DocumentBuilder, the best way is:
- Get the document as a byte array, perhaps by calling File.ReadAllBytes, or by serializing a stream to a byte array.
- Create a new MemoryStream
- Write the byte array to the memory stream. Note that you do not want to use the MemoryStream constructor that takes a byte array as an argument, as that creates a non-resizable memory stream, which means you can’t make changes to the document. Instead, you new up a MemoryStream using the default constructor, and then write the byte array into the MemoryStream as the first line in your using block.
- Open the MemoryStream using the Open-Xml-Sdk. Make modifications to the document.
- Once you drop out of the using block for the WordprocessingDocument, the memory stream will be updated. You can get the byte array by calling ToArray() on the MemoryStream.
- You can then new up the WmlDocument using the byte array, and do DocumentBuilder operations on it.
This sounds more complicated than it is. At any point in time, you have:
- A byte array.
- A memory stream.
- An opened WordprocessingDocument
- A WmlDocument created from the byte array, or retrieved from an Open-Xml-PowerTools function. You can get the byte array from a public property in this class.
I agree, it isn’t ideal. The root of this division is a difference in programming models – LINQ to XML is a better programming model than some of the classes in the Open-Xml-Sdk for doing certain types of transforms, so all of Open-Xml-PowerTools are written using LINQ to XML. Further, in order to make DocumentBuilder as robust and useful as possible, it was easier to write DocumentBuilder such that it was responsible for doing the actual opening of the documents in the source list. In particular, if a source references the same document twice, DocumentBuilder opens it twice, therefore, it is important to take unopened documents as input into DocumentBuilder.
I have had an idea of doing a much tighter integration of Open-Xml-PowerTools and the Open-Xml-Sdk, making your job easier, but this is not currently in my plans. But we never know, plans change.
No, that is not a feature of Open XML, nor of Word. It is a great idea, but there is no facility in the markup to bind chart values to XML in a custom XML part.
As far as I know, the only way to update a chart is to both drill down and change the cached values, and if you need to, then update the embedded XLSX. If you leave the XLSX in the DOCX package, and if you don’t update the values in it, will lead to a broken user experience where the values they see in the chart are changed to the values in the spreadsheet. You must either update the spreadsheet, or else remove it.
The Open-Xml-Sdk for JavaScript was designed (by me) to give almost line by line compatibility between Open-Xml-Sdk code in C#, and JavaScript code using the Open-Xml-Sdk for JavaScript. I have successfully translated thousands of lines of C# code to JavaScript, and it worked great. Unfortunately, I was not able to release that code publicly.
Translating just the ChartUpdater.cs to JavaScript is not a super huge project. But there is a fair amount to learn – you must be familiar with the idioms of LINQ to XML, as I re-implemented LINQ to XML for JavaScript, in order to facilitate just this type of translation of C# to JavaScript. Please check out the following:
Screen-Cast Series: Recursive Pure Functional Transforms
In particular, watch #11, #12, #13 in that series. But the rest of the screen-casts in that series are important – those techniques made me into a more effective XML developer.
I would love to port the entirety of Open-Xml-PowerTools to JavaScript – would be a useful project. But it is not going to happen in the near future, I don’t believe.
Cheers, Eric
March 16, 2016 at 4:11 am in reply to: Extract all charts and SmartArts from the Word Document. #2554Hi Prince,
What you need is the DocumentBuilder module in Open-Xml-PowerTools. Please see the screen-casts at the following link:
DocumentBuilder Developer Center
In particular, first watch this:
Short Introduction to DocumentBuilder
Cheers, Eric
Yes, you are right.
BTW, I now work on the SDK on a free basis, so could use a bit of help here.
Do one experiment – get version 2.6 of the SDK from GitHub, tweak the code, adding an entry into that enum, adding an additional case into GetMediadataPartTypeFromContentType, and see if this fixes the problem.
- This reply was modified 8 years, 8 months ago by Eric White.
Neither the Open-Xml-Sdk nor Open-Xml-PowerTools deal with the specifics of video or sound formats. As far as binary parts are concerned, they are blobs that you stream to a part, or copy from one part to another. The Open-Xml-Sdk and Open-Xml-PowerTools are not aware of the specific contents of any binary part.
When you insert an MP4 into a presentation, does it play? I wonder if PowerPoint converts the video to avi when inserting. Can you look and see?
- This reply was modified 8 years, 8 months ago by Eric White.
The license is Microsoft Public License, which is not copy-left. Lets you do what you want with the code.
No, no ExcelBuilder (yet).
Regarding converting objects from one format to another, my idea is to make HTML/CSS the intermediate format – convert from SpreadsheetML to HTML/CSS, then convert from HTML/CSS to formatted WordprocessingML.
However, I have not had the opportunity to implement this, and chances are I will not in the foreseeable future. I’m afraid that you will need to implement the functionality that you need yourself.
You will want to use PresentationBuilder. You would have to duplicate all of the functionality in PresentationBuilder if you intended to use the Open-Xml-Sdk directly.
March 12, 2016 at 10:49 pm in reply to: PresentationBuilder cannot copy video slides correctly #2531No, you can’t create folder layout exactly as generated by PowerPoint. But it should not matter.
[Content_Type].xml is created implicitly by System.IO.Packaging when you create a package. When you maintain a package, adding parts, you specify the content type, and System.IO.Packaging will add new entries into [Content_Type].xml. You should never need to maintain this explicitly.
March 12, 2016 at 10:44 pm in reply to: Merge 3 document, discard footer or header separatly into one document #2530Sorry, not clear. Is it a bug in your code, or in DocumentBuilder?
GetXDocument and PutXDocument are convenience functions that make it easier to work with LINQ to XML using the Open-Xml-Sdk. You can call GetXDocument multiple times and it will de-serialize it only once. The annotations are on the Open XML parts within a package. You can think of annotations as strongly-typed ‘user data’ for a part within a package.
Annotations are in-memory only. They have no affect on rendering.
March 12, 2016 at 12:42 am in reply to: Why image/jpeg file extension is changed to .bin after slide copy? #2524If you determine with certainty that the name of the file causes PowerPoint to not play the video, then you can use System.IO.Compression to open the ZIP and fix the file name.
Awesome! I’m glad your issue is resolved.
March 12, 2016 at 12:37 am in reply to: Why image/jpeg file extension is changed to .bin after slide copy? #2522Are you sure that this is the reason that files are not playable in the PPTX? In general, Open XML does not care what the exact file name is. It only cares what the relationship type is, and what the content type for the part is.
The behavior you see where the file is renamed with extension of .bin, this is functionality in the Open-Xml-Sdk, not Open-Xml-PowerTools.
We need to ascertain with certainty whether the name of the file has significance in PowerPoint. It should not, but who knows what they did inside PowerPoint.
-
AuthorPosts