Quantcast
Channel: Open XML Format SDK forum
Viewing all 1288 articles
Browse latest View live

Maintain paragraph margins in Open XML after a header

$
0
0

I am generating a docx document with Open XML and I have a problem. Although I has been able to apply styles to the headers, I want to apply the margins of the headers to the following paragrpahs, in the same way that word does. For example, if you add a Title with Header 2 the following paragraph has the same left margin that the header 2 style.

I am adding the data of the paragraph in the following code:

DocumentFormat.OpenXml.Wordprocessing.Paragraph pDesc = body.AppendChild(newDocumentFormat.OpenXml.Wordprocessing.Paragraph());DocumentFormat.OpenXml.Wordprocessing.Run rDesc = pDesc.AppendChild(newDocumentFormat.OpenXml.Wordprocessing.Run());DocumentFormat.OpenXml.Wordprocessing.Text tDesc = rDesc.AppendChild(newDocumentFormat.OpenXml.Wordprocessing.Text(mainNode.Description));
pDesc.ParagraphProperties=newDocumentFormat.OpenXml.Wordprocessing.ParagraphProperties();

I suppose that the solution is the paragraph properties but I don't know if I have to create a style for each kind of paragraph after each kind o header (header1, header2, header3...) or there is a way of saying the paragraph applys part of the style of the header.

Thanks a lot in advance.


validate xlsx file with xsd using open xml

$
0
0

hello,

i would to know how can i validate an xlsx file with xsd using open xml?

because trough XmlReader i get an error :data at the root level is ivalid.line 1 position1

i used this code but did'nt work.

 string wXsd =@"D:\Test.xsd";
            string wExc = @"D:\definitivo.xlsx";
            try
            {

                XmlReaderSettings booksSettings = new XmlReaderSettings();
                booksSettings.Schemas.Add("http://www.w3.org/2001/XMLSchema-instance", wXsd);
                booksSettings.ValidationType = ValidationType.Schema;
                //   booksSettings.ValidationEventHandler += new ValidationEventHandler(booksSettingsValidationEventHandler);

                XmlReader books = XmlReader.Create(wExc, booksSettings);

                while (books.Read()) { }
            }
            catch (Exception)
            {
                
                throw;
            }

thanks in advance

Bad fill style in table headers with OpenXML

$
0
0

I am generating documents with OpenXML and adding tables, and I have found a strange issue. I am generating the headers with the following code:

 DocumentFormat.OpenXml.Wordprocessing.TableRow tr = new DocumentFormat.OpenXml.Wordprocessing.TableRow();

            // Create a cell.
            DocumentFormat.OpenXml.Wordprocessing.TableCell tc1 = new DocumentFormat.OpenXml.Wordprocessing.TableCell();

            // Specify the width property of the table cell.
            tc1.Append(new DocumentFormat.OpenXml.Wordprocessing.TableCellProperties(
                new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" }));

            tc1.TableCellProperties.Shading = new Shading() {
                Color = "auto",
                Fill = HexConverter(System.Drawing.Color.LightGray),
                Val = ShadingPatternValues.Clear
            };

            DocumentFormat.OpenXml.Wordprocessing.Paragraph p1 = tc1.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Paragraph());
            DocumentFormat.OpenXml.Wordprocessing.Run r1 = p1.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Run());
            DocumentFormat.OpenXml.Wordprocessing.Text t1 = r1.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Text("Factor"));            

            r1.RunProperties = new DocumentFormat.OpenXml.Wordprocessing.RunProperties();
            r1.RunProperties.RunFonts = new RunFonts();
            r1.RunProperties.RunFonts.Ascii = "Arial";
            r1.RunProperties.FontSize = new FontSize() { Val = "24" };
            r1.RunProperties.Bold = new Bold() { Val = OnOffValue.FromBoolean(true) };

            // Append the table cell to the table row.
            tr.Append(tc1);

But when the table is visualized in word, although the header cell is filled with gray color, the intial margin inside the cell appears in white. if I open the docx file with other controls that can show docx it appears in the right way, but not in Word. Any ideas about what is happening?

thanks a lot

Generating Visio Drawing 2013 file with open XML in .NET

$
0
0

Hi Team,

Looking for a server side solution to generate Visio 2013 drawing using Visio template & stencils with open XML in .NET.

Please provide the solution / samples / references for the same at the earliest.

Thank you in advance.

Regards,
Badari

Programmatically Update Multiple External Data Connections in Excel 2010

$
0
0

I am using the following code given in an example here  http://msdn.microsoft.com/en-us/library/dd941886(v=office.11).aspx

Private Sub UpdateConnectPath(ByVal strSourceFile As String)
   Dim oxmlNode As XmlNode

   Try
      ' Open the workbook.
      Dim wkb As SpreadsheetDocument = SpreadsheetDocument.Open(strSourceFile, True)

      ' Manage namespaces to perform Xml XPath queries.
      Dim nt As NameTable = New NameTable
      Dim nsManager As XmlNamespaceManager = New XmlNamespaceManager(nt)
      nsManager.AddNamespace("sh", spreadsheetmlNamespace)

      ' Get the connections part from the package.
      Dim xdoc As XmlDocument = New XmlDocument(nt)
      ' Load the XML in the part into an XmlDocument instance.
      xdoc.Load(wkb.WorkbookPart.ConnectionsPart.GetStream)

      ' Find the SourceFile attribute.
      oxmlNode = xdoc.SelectSingleNode("/sh:connections/sh:connection/@sourceFile", nsManager)

      ' Update the files processed counter.
      If (oxmlNode IsNot Nothing And oxmlNode.Value <> Me.txtNewLocation.Text) Then
         numChanged += 1
      End If

      ' Replace the old path with the new path.
      oxmlNode.Value = Replace$(oxmlNode.Value, Me.txtOldLocation.Text, Me.txtNewLocation.Text)
      xdoc.Save(wkb.WorkbookPart.ConnectionsPart.GetStream)

      ' Find the connection string attribute.
      oxmlNode = xdoc.SelectSingleNode("/sh:connections/sh:connection/sh:dbPr/@connection", nsManager)

      ' Replace the old path with the new path and save the document.
      oxmlNode.Value = Replace$(oxmlNode.Value, Me.txtOldLocation.Text, Me.txtNewLocation.Text)
      xdoc.Save(wkb.WorkbookPart.ConnectionsPart.GetStream)

      Catch
         ' Some files have no external connections so ignore any errors.
      End Try

End Sub

but unable to update the connection string. When i run the application it would appear that no connections are being found at line: 

oxmlNode = xdoc.SelectSingleNode("/sh:connections/sh:connection/@sourceFile", nsManager)

My goal is to update the connection string for several hundred workbooks in a single directory.

Any help would be greatly appreciated. I am trying to update the excel web query URL using 0ffice 2010 and XML SDK 2.5






How to remove empty value mail merge fields?

$
0
0

Hi,

I am trying to generate mail merge document using open xml. I can generate the document but if there was no value found for a merge field, it leaves an empty space. If there is no value found for a mail merge field I would like to remove/delete it so the finally generated document does not have any blank spaces.

Regards

Bubble Chart from Excel to Word not working

$
0
0

I am currently working on a project to update the chart from excel to word. We generate an excel document in the linux environment, which uses the Open office XML standards to generate the excel file. 

And then we use those excel files to embed charts into word documents in a specific location. Almost all charts work fine in both environment except for the Bubble chart. Which shows one (either yellow or blue) color for the chart, i mean the whole chart is filled with one color and scale is seen except that, without showing any bubbles. However the very same chart.xml file works well for excel.

Don't know whats going wrong, or if this is something thats not supported by word, but supported by excel?

Another thing which I observed is, If i open the excel file and save it without changing anything. The bubble chart gets generated on the word. On a save the underlying chart.xml gets updated, which then works with word nicely. Since this is an automated program, I cant open it and save it over and over.

Any help will be greatly appreciated.


Thanks,
Dhruv S.

How to determine the default path of Normal.dot using the .Net C# programming language?

$
0
0

I need to determine the absolute path, where the Normal.dot file is located on a target system.

As i already found out, the default path is as following:

C:\Users\SomeUserName\AppData\Roaming\Microsoft\Templates

I do not intend to hard code the absolute path into my application, therefore is need to determine it dynamically using OpenXML.

Question: How to do this?

Many thanks in advance

Martin


Have a Worksheet, how do I get its SpreadsheetDocument?

$
0
0

I am trying make my code more efficient. Have looked at the documentation, but this is not easy to find.

Given a Spreadsheet.Worksheet, how do I find its parent Packaging.SpreadsheetDocument?

Through Ancestor, perhaps?

TIA

Generated docx, problem with editing in OWA/WAC

$
0
0

Hi!

I have successfully created a docx from a dotx with C#/OpenXML. I added an XML with some properties and the docx gets populated just fine with the custom values. I upload the document to SharePoint Online and can preview the document just fine. When i try to edit the document all the custom properties that have been populated are grayed out and can't be edited. I guess this is a limitation in OWA/WAC but i would like to get this confirmed and i have not been able to find any information regarding this. I've also tried to use "built in" properties like Title, Author and so on but the result is the same.

Thank you!

EDIT:

If there is any workaround for the "issue" i would appreciate any guidance. Is there any way to "print" the contents of the document to a new blank docx so that all the mappings/xml-stuff are removed? If thats possible that would absolutely be a good workaround.

Setting image size in XML using wp:extent and a:ext

$
0
0

I am having an XML file generated dynamically (using ruby) and I'm simply having an issue with image sizing. A few people online have mentioned that they're set based on the pixel dimensions of the image. I'm not finding this to be the case. 

Here's one link in particular that I was looking at: http://openxmldeveloper.org/discussions/formats/f/15/p/396/933.aspx. 

The reason I know this may not be 100% the case is because I basically opened a word document, inserted 2 screenshots, and I compared the output of the 9525 (PMU) * every pixel and got different values. 

If I take a look at image1 for example, it's 802x164, and image2 is 722x503. The wp:content and a:ext values that were generated (in respective order) are:

<wp:extent cx="5153025" cy="1053736"/><a:ext cx="5153025" cy="1053736"/>
<wp:extent cx="5553075" cy="3868694"/><a:ext cx="5553075" cy="3868694"/>

So 802 * 9525 = 7639050 and this doesn't exist anywhere in that XML output.

My goal here is to make sure that the images I'm referencing from XML are properly sized. I would like the size of the image in the word doc to be the exact size of the image itself.

Any help would be GREATLY appreciated. I've been looking around for hours and still coming up empty.




Get MS Word real page number using Open XML SDK 2.5

$
0
0
I'm using Open XML SDK 2.5 in the recent project.
I use the following code to get the page number from the word document:

    ExtendedFilePropertiesPart extendedPart = document.ExtendedFilePropertiesPart;
    pageNumber = int.Parse(extendedPart.Properties.Pages.Text);

The app.xml file may look like this:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
        <Template>Normal.dotm</Template>
        <TotalTime>1</TotalTime>
        <Pages>150</Pages>
        ......

But sometimes the <Pages> node value does not match the real page number!
For example:when opening a word document with 150 pages, modify sometings, then save and close the file quickly before it finishes rendering the contents. Then you may find that the <Pages> node value in the app.xml is not correct!
(Maybe only 3 other than 150 !)

We can not use the PIA (Office Primary Interop Assemblies) through it could get the right page number.
The question is it is possible we could get the right page number by using the Open XML SDK 2.5?

Is the DocumentFormat.OpenXml.xml needed for deployment?

$
0
0

For our production servers, I will not be installing the OpenXML SDK on the servers.

I'm planning on copying the DocumentFormat.OpenXml.DLL to the work directory along with our EXE.  But does the DocumentFormat.OpenXml.xml file need to be included as well?

Thanks.

Replacing a prenamed image in a document

$
0
0

Hi

I have a task in where I recieve a document with pre-formatted named images and where I want to replace the imagepart in the document with a new picture.

I now I can change the image info with feeddata-functions for the imagepart, but my problem is to locate and identify the image.

In the image below I have cut out the run-part och the document where the picture is placed.
Here I can see that the name of the picture is Image_MainImage, and the relation ID of it is rId8.

Can anybody supply som code (VB or C#) on how to retrieve the relation ID?
With the ID I believe it should be easy to replace the imagepart.

Thanks in advance


Best Regards Peter Karlström Midrange AB, Sweden



Getting HTML text with in a table cell

$
0
0

Hi 

I am using Open XML to read the values inside the cell. I am able to get the plain text inside the cell of a table using innerText property as shown below - 

     

TableRow row = table.Elements<TableRow>().ElementAt(0);
DocumentFormat.OpenXml.Wordprocessing.TableCell cell = row.Elements<DocumentFormat.OpenXml.Wordprocessing.TableCell>().ElementAt(1);

 String value = cell.InnerText;

I would like to know how can I get directly rich text inside the cell using the open xml api.

Thanks

Prashant


prashant


reading a simple table cell from a word document

$
0
0

hi,

i have a really basic question that i don't seem to understand:

i am trying to read a table from a word document witch has 3 cells per row, everything works fine except one thing:

on cells that have more then one line of text, i don't know why but sometimes "word" saves the text in 2 paragraphs sometimes in 2 different runs, sometimes in 2 different texts with a "br" in the middle and sometimes a combination of them all...

can anyone help me =[

i need a simple way of reading a cell content

thank you very much in advance

jony

Replacing av FORMFIELD in Word with text

$
0
0

Hi

In one of my projects I need to locate some document FORMFIELDS in Word and replace them with text.

I can locate the FORMFIELD in the document but the only text to change here is the Default text value, which is not correct.

I have been exploring a document "before" and "after" with the Open XML SDK tool I it seems I should remove the FORMFIELD and replace it with a Run Text object.

Below is the document XML part "before" it's changed:

<w:r><w:rPr><w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial" /></w:rPr><w:fldChar w:fldCharType="begin"><w:ffData><w:name w:val="Text3" /><w:enabled /><w:calcOnExit w:val="0" /><w:textInput><w:default w:val="[Contract No]" /></w:textInput></w:ffData></w:fldChar></w:r><w:bookmarkStart w:name="Text3" w:id="0" /><w:r w:rsidRPr="0052037E"><w:rPr><w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial" /><w:lang w:val="en-US" /></w:rPr><w:instrText xml:space="preserve"> FORMTEXT </w:instrText></w:r><w:r><w:rPr><w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial" /></w:rPr></w:r><w:r><w:rPr><w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial" /></w:rPr><w:fldChar w:fldCharType="separate" /></w:r><w:r w:rsidRPr="0052037E"><w:rPr><w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial" /><w:noProof /><w:lang w:val="en-US" /></w:rPr><w:t>[Contract No]</w:t></w:r><w:r><w:rPr><w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial" /></w:rPr><w:fldChar w:fldCharType="end" /></w:r><w:bookmarkEnd w:id="0" />

Below is the same part in the document "after":

<w:r w:rsidRPr="0052037E" w:rsidR="00291444"><w:rPr><w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial" /><w:lang w:val="en-US" /></w:rPr><w:tab /></w:r><w:r w:rsidRPr="00094E54" w:rsidR="00094E54"><w:rPr><w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial" /><w:lang w:val="en-US" /></w:rPr><w:t>691 - F0045</w:t></w:r>

How can this change in the document be done?
Anybody has some VB or C# sample?


Best Regards Peter Karlström Midrange AB, Sweden


Updating contents of the formula cell using OpenXML SDk

$
0
0
Hi,
I'm using OpenXML SDK to fill in a series of cells which come under the scope of a formula in an existing excel template.
Although the cells inside the range of the formula are filled up, the value in the formula cell is not updated.

Neither the Calculate Now option nor the Calculate Sheet option seems to be working. The only way i'm able to update the formula cell is by going into Sheet properties in the developer tag and Set/Reset EnableCalculation option to True.

Is there a way of doing this through OpenXML SDk programmatically? Any other options?

Any help would be appreciated

Predefined Number formats < 164 question

$
0
0

Being that the numFmtId below 164 are predefined and not stored in the numFmts of the stylers.xml file of a spreadsheet, does that mean that I have to create an internal lookup table of the values and corresponding formula values so I know how to apply them to a particular cell value if it has one of those formats?

As an example, if cell "A1" has a value of "987654321" and has a numeric format of numFmtId="3" (formula: #,##0) and I want to write the value of "987,654,321" to an ASCII flat file, I will have to look this up in my own "lookup" table to produce the proper string.Format statement (parsing for special characters, etc.).

Or is there another means of doing this?

Thanks.


Generating dynamic excel spreadsheet with WebQuery using OpenXML SDK

$
0
0

Hi,

I have generated an excel workbook using OpenXML. This uses data from DB for sheet data and column validations.

I want to make this excel document a dynamic one so the user can refresh any time to get latest values for those columns.

I am aware this can be done using Web Queries (Connection part) which needs inputs like URL and POST data string. I have created a webpage which will return data to excel document on refresh.

Can I return my excel document or sheet data as is so that I wont need to look at validations again?

How can I reuse the excel generation code for dynamically pulling the data?

Thanks,

Tushar

Viewing all 1288 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>