Eric White

Forum Replies Created

Viewing 15 posts - 151 through 165 (of 253 total)
  • Author
    Posts
  • in reply to: Get Highlighted Text from .docx #3468

    Eric White
    Keymaster

    It is quite a bit more complicated than the approach you are taking. You are selected the descendant ‘w:highlight’ elements, but this is not where the text is stored. The text is in the w:t element that is inside a w:r element that contains the w:rPr element (the run properties), which contains the w:highlight element.

    <w:p>
      <w:r>
        <w:rPr>
          <w:highlight w:val="yellow"/>
        </w:rPr>
        <w:t>Test</w:t>
      </w:r>
    </w:p>

    You have to first select the runs that have the w:rPr elements that contain the w:highlight element with your desired value. Then after selecting those runs, you have to select the child w:t elements (and there may be multiple) that contain the actual text. To complicate matters further, that highlight element may be in the run properties in a style, so you would have to look at the style part, find the style, and see if the w:highlight element is in the run props for a style. Also, that character style may itself derive from another character style, where the w:highlight element is defined.

    Document formats are complicated, and for good reason – the structure of the documents themselves are complicated.

    I recommend that you watch the Introduction to Open XML screen-cast series. After you have watched those screen-casts, then watch the Introduction to WordprocessingML screen-cast series.

    in reply to: How do i use openXML SDK for javascipt With Office.Js #3467

    Eric White
    Keymaster

    I have created a couple of JavaScript add-ins for Office, but to date, have only done so for Word, so have no experience with using the Excel JavaScript API. I am not certain whether there is any JavaScript API for Excel that will return the markup, including formatting, for the selected range. It appears that you can get, for instance, the fill color, the font color, wrapping, etc. for a range.

    http://dev.office.com/docs/add-ins/excel/excel-add-ins-javascript-programming-overview?product=excel

    But the getSelectedDataSync method (using coercion type of OOXML) only works for Word.

    http://dev.office.com/reference/add-ins/shared/document.getselecteddataasync

    I don’t believe at this point, you can get the OOXML markup. You have to get the formatting using the APIs.

    in reply to: Charts #3465

    Eric White
    Keymaster

    The answer to your question about why files are copied from “../../” to the Temp folder, and then the updated chart file is created there from the copy is very simple. I do that with almost all my examples, so that when I am manually validating the correct functionality, both the ‘before’ and ‘after’ files are in one location, for my own ease of opening them and seeing if the code worked properly.

    I’m happy you are able to modify the ChartUpdater to get the results you want. In one way, this is the main intention behind the code – to show the basic plumbing of how to do it, and then you can modify as appropriate for your scenario.

    in reply to: Generated Word Doc Right Justify Numbered List #3462

    Eric White
    Keymaster

    I am not sure exactly what you are using when you refer to the ‘Word Document Generator Library’. Can you provide a link

    However, it is probably possible to post-process the document after you generate it, tweaking the formatting for the numbering as you desire. I say ‘probably’ because I am not clear on exactly what you are using, and what exactly is the form of the Open XML markup after you generate it.

    Have you taken a look at DocumentAssembler, which is a module in Open-Xml-PowerTools?

    DocumentAssembler Developer Center

    I am quite sure (although I haven’t tried it) that you could set up the numbering exactly the way you want it, and use a Repeat / EndRepeat to create repeating content, then use Content within that to specify the contents of each list item, and it will produce numbering in the exact format you want.


    Eric White
    Keymaster

    Hi Paul,

    I’m sorry – I thought you were referring to the new JavaScript APIs in the new Apps for Office approach to extending Microsoft Office. My mistake. (For what it’s worth, I am a big fan of this new way to extend Office – vastly superior over extending using VSTO. Deployment is a breeze compared to VSTO.)

    So, sorry, forget what I said.

    I think that what you are seeing is the behavior of the actual COM libraries. You are using the API in the COM libs that enable you to get the markup for the current selection, and that API returns what it returns, and you have no control over it. Altering the behavior of the COM libraries is not possible.

    VSTO is a (mostly) thin managed wrapper over the COM libraries, so you are still at the mercy of the COM libraries when using VSTO.


    Eric White
    Keymaster

    That blog post from Brian Jones is specifically about the idea that you need to include the xml:space=”preserve” attribute for a w:t element, if the text in that w:t element contains spaces at the beginning or end of it.

    This is, I believe, unrelated to the issue you are facing, which is variances in the markup that the JavaScript API returns depending on whether you select various combinations of spaces before and after the words you are interested in.

    Those JavaScript APIs are a ‘black-box’ to a great extent. They return what text they return based on what the user has selected, and you have no control over what they return. It certainly does seem like fairly random behavior, but I believe that you have little or no control over this behavior.

    One idea – I’m not certain if this idea will be fruitful – but worth a bit of research. It is possible that the source code for those JavaScript APIs are available on GitHub or elsewhere. Certainly it is available as minimized JavaScript, which you can retrieve because you have the URI to that JavaScript in the source for your app. It would be interesting to see if this behavior is implemented in the JavaScript API, or if this behavior is implemented at a deeper level. If it is implemented in the JavaScript API, it might be possible that you could modify that code and alter the behavior. If it is implemented in the COM libraries that the JavaScript APIs call, then there most probably is nothing that you can do to impact this behavior.


    Eric White
    Keymaster

    You cannot prevent Microsoft Word from doing this.

    Instead, I recommend that when you generate the document, create a styles part and put the docDefaults in it, with the default paragraph and run properties that you want for your document.

    in reply to: Charts #3457

    Eric White
    Keymaster

    Hi,

    Unfortunately, as you know, that is not a feature of DocumentAssembler. It is a great idea, though.

    I recommend the following approach –

    • Include a ‘template’ chart in your template document. You will need to identify this ‘template’ chart in some fashion. One approach that I have used successfully in the past is to insert a paragraph before the chart that contains a specific GUID.
    • Then produce the new document using DocumentAssembler.
    • Write some code that goes into the generated document, and finds the paragraph with the specific GUID.
    • Get your data for the chart in the form that ChartUpdater wants
    • Your code can then find the chart immediately following, and use ChartUpdater to update the data.

    I have added this idea to my list of requested enhancements for DocumentAssembler. But I do not have a schedule for this. Probably not soon, given my current committments.

    Cheers, Eric

    in reply to: Add table of contents after first page #3456

    Eric White
    Keymaster

    You need to find the paragraph in the document before which you want to add the TOC, and pass that paragraph to the AddToc method.

    The question for you is how will you find the first paragraph after your cover page?

    If your cover page has a page break at the end, then that is probably the easiest way to find it.

    What does the markup for your cover page look like? Do you have a page break at the end of it?

    in reply to: Alignment of text in header #3453

    Eric White
    Keymaster

    Hi,

    The best way to accomplish this is by using tabs.

    When you need to learn about the markup for any specific feature of Word and Open XML, the best approach is to use that shown in the following screen-cast:

    How to Research Open XML Markup

    The idea here is to set tabs for the locations where you want text to align, and then use tabs between your content, so that the content aligns under the header information.

    First, you will want to show the ruler, so that you can set tabs. On the View tab of the ribbon, in the “Show” section, you click the Ruler checkbox.

    Then set the tabs as appropriate for your content.

    Create a document that is a prototype of how you want your generated document to look.

    Use the Open XML Package Editor Power Tool for Visual Studio to examine the markup, as shown in the above screen-cast. See this link for more information. It is screen-cast 4 in the series:

    Introduction to Open XML Screen-Cast Series

    <w:p>
      <w:pPr>
        <w:tabs>
          <w:tab w:val="left"
                  w:pos="2880"/>
        </w:tabs>
      </w:pPr>
      <w:r>
        <w:t>In column 1</w:t>
      </w:r>
      <w:r>
        <w:tab/>
        <w:t>In column 2</w:t>
      </w:r>
    </w:p>

    You can see the position of the tab in the w:pPr/w:tabs element.

    You can see the location of the tab in the paragraph – it is the w:tab element that is a child of the w:r element.

    When we look at the header part, we see the following, which is identical to the markup in the main document part:

    <w:p>
      <w:pPr>
        <w:pStyle w:val="Header"/>
        <w:tabs>
          <w:tab w:val="left"
                  w:pos="2880"/>
        </w:tabs>
      </w:pPr>
      <w:r>
        <w:t>Heading 1</w:t>
      </w:r>
      <w:r>
        <w:tab/>
        <w:t>Heading 2</w:t>
      </w:r>
    </w:p>
    

    Those tabs are in TWIPS, which is 1/20 of a point. That is the unit of measure for those tabs.

    In addition to watching all of the screen-casts in the Introduction to Open XML series, I also recommend that you watch the screen-casts in the Introduction to WordprocessingML series.

    Cheers, Eric


    Eric White
    Keymaster

    Hi Krzysztof,

    There are lots of factors that can impact memory usage. Also OutOfMemoryException sometimes does not mean that the program is out of memory – it can mean that the memory is too fragmented to allocate the desired amount of memory.

    The first thing that I recommend that you do is to build in 64-bit mode. I have encountered situations where the Open-Xml-Sdk ran out of memory in 32-bit mode, but did not in 64-bit mode.

    Certainly, the memory usage profile for 2.6 will be different from 2.5. Version 2.6 is based on System.IO.Compression, which will alter the pattern of memory usage. Version 2.5 was based on a weird, internal implementation of the ZIP file format, and I don’t know the details of the impact of these two libraries on memory usage. I am not surprised that they are different.

    Unfortunately, I have been pulled from that project. I am no longer maintaining the Open-Xml-Sdk.

    I suggest that you try with 64 bit mode. If that does not fix your issue, then I suggest that you create an issue on GitHub for this.

    Cheers, Eric

    in reply to: Add table of contents into second page of word document #3438

    Eric White
    Keymaster

    Hi Sahil,

    The first question is how do you know the end of the cover page? Do you have a hard page break afterwards?

    The key point is that you need to find the first paragraph of the second page, and add the altChunk element immediately before.

    Unfortunately, my current schedules and deadlines prohibit me from writing this sample code, but I’m sure that you can work it out. Have you viewed the introduction videos for Open XML and WordprocessingML?

    Introduction to Open XML

    Introduction to WordprocessingML

    From those videos, you can learn how to make the appropriate changes to your code so that you can add the TOC anywhere you want to add it.

    Cheers, Eric

    in reply to: System.IO.IOException after upgrade to OpenXML SDK 2.6 #3434

    Eric White
    Keymaster

    The new System.IO.Packaging is based on the System.IO.Compression namespace, and a constraint of System.IO.Compression is that you can’t open a file in the zip package more than once for writing. This makes sense – what would the behavior be if a file is opened more than once for writing? It would be pretty random.

    If you are seeing this in code that is based on the Open-Xml-PowerTools, then you will need to upgrade to the latest. I have fixed all such issues in Open-Xml-PowerTools.

    If you are seeing this in code that you wrote, then you will need to find out why you are opening a part for writing more than once, and then change your code so that you don’t do this. In most cases, you might be opening a part for writing where you actually didn’t need to do so – in one location in your code, you might be opening the document for writing, where you don’t actually change the markup, whereas in another area of your code, you will be writing to the part. In this case, change your code so that you are opening for writing only when you actually need to do so.

    I hope this made sense to you. This is the gist, and it is a hard limitation with System.IO.Compression, so the issue must be fixed.

    in reply to: Streaming .xlsx #3410

    Eric White
    Keymaster

    It is easy to create a huge file using a streaming approach.

    Screen-cast: Using Open Xml and Linq-to-Xml in a streaming fashion to create huge spreadsheets

    I imagine that one could start with this code and stream to the correct opened stream that you are using to download the file. You might have to use XmlWriter. I have never had occasion to write this code, so haven’t worked out the plumbing details.

    Cheers, Eric

    in reply to: Reading an Excel file from Sharepoint #3409

    Eric White
    Keymaster

    Hi Vimal,

    This is really a JavaScript/framework question, and I don’t know the answer off the top of my head. I know how to do it in C#, but haven’t ever written this code for JavaScript. Would just have to google it.

    Cheers, Eric

Viewing 15 posts - 151 through 165 (of 253 total)