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

Issue in Insert value in sharedstringtable

$
0
0

Hi,

   I try to insert following string in one of the cell in my excel sheet through open xml, i am facing the issue in display the string value

input string value = "    Hello World"

Expected Result ="    Hello World"

Actual Result  = "Hello World"

Here issue is left hand side of the string is trim automatically, how i can solve the problem, please help me.

This is the code i am using to insert the string value in sharedstringtable, i guess the problem is in inserting the value in sharedstringtable.

int index = InsertSharedStringItem(wbPart,"    Hello World")

private int InsertSharedStringItem(WorkbookPart wbPart, string value)
        {
            int index = 0;
            bool found = false;
            var stringTablePart = wbPart.GetPartsOfType<SharedStringTablePart>().FirstOrDefault() ??
                                  wbPart.AddNewPart<SharedStringTablePart>();

            // If the shared string table is missing, something's wrong.
            // Just return the index that you found in the cell.
            // Otherwise, look up the correct text in the table.

            var stringTable = stringTablePart.SharedStringTable ?? new SharedStringTable();

            // Iterate through all the items in the SharedStringTable. If the text already exists, return its index.
            foreach (SharedStringItem item in stringTable.Elements<SharedStringItem>())
            {
                if (item.InnerText == value)
                {
                    found = true;
                    break;
                }
                index += 1;
            }

            if (!found)
            {
                stringTable.AppendChild(new SharedStringItem(new Text(value)));
                stringTable.Save();
            }

            return index;
        }


How to read /process numbers that have a "General" format (NumberFormatId = 0)

$
0
0

I found this on stackoverflow that describes the question I have, but the "answer" doesn't really address how to determine "what" the displayed value in Excel is.  Maybe it can't be determined.  If that's the case, that's okay because I can tell customers there's no way we can accurately process numeric fields with a "General" format.

http://stackoverflow.com/questions/5859496/inconsistent-visualization-of-numerical-values-in-excel-2007-vs-the-underlying-x

I have a spread sheet where I've left all the cell formats at "General".  All the values I entered have 1 position after the decimal place:

As an example, here are how some of the values are retrieved in my test program:

Displayed value     Actual value from file
2.1                       2.2000000000000002
2.2                       2.2000000000000002
3.1                       3.1
3.2                       3.2
3.7                       3.7
4.1                       4.0999999999999996

Again, I don't care "why" they are stored the way they're stored, but am trying to determine if there's a way to determine the "displayed" format, when a true numbering format isn't assigned.

Thanks.

Get Page Number of Comment using Open XML SDK

$
0
0

Can anyone help me in getting the page numbers of comments entered in a word document using Open XML SDK in C#

Extract from my code:

using (WordprocessingDocument wordDoc =
                            WordprocessingDocument.Open("C:/temp/doc1.docx", false)) {
                            WordprocessingCommentsPart commentsPart =
                                wordDoc.MainDocumentPart.WordprocessingCommentsPart;

                            if (commentsPart != null && commentsPart.Comments != null) {
                                foreach (Comment comment in commentsPart.Comments.Elements<Comment>()) {

                                    SPList list = web.Lists["UserFeedback"];

                                    SPListItem itemToAdd = list.Items.Add();

                                    itemToAdd["Title"] = filename.Name.ToString();
                                    itemToAdd["Feedback"] = comment.Author.InnerText;
                                    itemToAdd["UserComments"] = comment.InnerText;
                                    itemToAdd["UserInitials"] = comment.Initials;
                                    itemToAdd["PageNumber"] = "";
                                    itemToAdd["Section"] = "";
                                    itemToAdd.Update();
                                }
                            }
                            wordDoc.Close();
                            wordDoc.Dispose();
                        }

Any help is appreciated.

Regards,

Vijay.


Merging sheets creates conflict when images exists on both sheets

$
0
0

Hi

I have a solution of creating and merging Excel-files in a webservice.

This has been working fine, until both of the Excel-files began to contain images.

As an example, the service recieves one Excel template and one Excel workbook.
The goal is to create a new Excel workbook consisting of the supplied parts.

Since the template is indeed a template (xltx), I start of by working with the workbook.
I then merge all worksheets from the template file to the workbook file.
This is done in memory with the help of EPPlus version 3.1.2 and the following routine where grmName is path to the template file and wbkName is path to the workbook:

Friend Sub XLAddInfoSheets(ByVal grmName As String, ByVal wbkName As String)

        Dim targetFI As New FileInfo(wbkName)
        Dim templateFile As String = grmName
        Dim ContentOverrides As New ArrayList

        Try
            Using t As New ExcelPackage
                Using Tstream As New FileStream(wbkName, FileMode.Open, FileAccess.ReadWrite)
                    t.Load(Tstream)
                End Using
                Using d As New ExcelPackage
                    Using Dstream As New FileStream(templateFile, FileMode.Open)
                        d.Load(Dstream)
                    End Using
                    For Each dws In d.Workbook.Worksheets
                        Dim addOK As Boolean = True
                        If dws.Name = "Försättsblad" Or dws.Name = "Cover Page" Then
                            Dim tmpName As String = dws.Name
                            For Each twx In t.Workbook.Worksheets
                                If LCase(twx.Name) = LCase(tmpName) Then
                                    addOK = False
                                    Exit For
                                End If
                            Next
                            If addOK Then
                                t.Workbook.Worksheets.Add(tmpName, dws)
                                t.Workbook.Worksheets(tmpName).Hidden = dws.Hidden
                            End If
                        End If
                    Next
                End Using

                t.SaveAs(targetFI)
            End Using
        Catch ex As Exception
            WriteLogg("Could not merge coverpages from the template.", ex.Message, logFile)
            Exit Sub
        End Try

    End Sub

When opening the created file (if both the template and the workbook contains images) shows a repairable error.
After the repair is made, the images in the inserted sheets is actually an image from the original workbook, not the same image as in the template sheet.
I realise that there is a mixup of relations causing this, so I tried looping through the images in the inserted sheets and delete the original image (DrawingPart) and add the image again.

This is done with the following code where wbPart is the actual Workbookpart and imagePath is path to the image which is extracted to disk earlier:

    Private Sub XLRelateImages(ByVal wbPart As WorksheetPart, ByVal imagePath As String)

        Try
            Dim drawingPart = wbPart.DrawingsPart
            If drawingPart IsNot Nothing Then
                Dim doc As New XmlDocument()
                doc.Load(drawingPart.GetStream())
                Dim ns As New XmlNamespaceManager(doc.NameTable)
                ns.AddNamespace("a", "http://schemas.openxmlformats.org/drawingml/2006/main")
                ns.AddNamespace("xdr", "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing")
                Dim list As XmlNodeList = doc.SelectNodes("/xdr:wsDr/xdr:twoCellAnchor/xdr:pic/xdr:blipFill/a:blip", ns)
                Dim pairList As New List(Of KeyValuePair(Of String, String))()
                For Each node As XmlNode In list
                    For Each attribute As XmlAttribute In node.Attributes
                        Dim pair As New KeyValuePair(Of String, String)(attribute.Value, attribute.Name)
                        pairList.Add(pair)
                    Next
                Next
                For Each image As KeyValuePair(Of String, String) In pairList
                    Dim id As String = image.Key
                    Dim name As String = image.Value
                    Dim oldPart As OpenXmlPart = Nothing
                    If name = "r:embed" Then
                        ' get ImagePart via id
                        oldPart = drawingPart.GetPartById(id)
                        ' delete ImagePart
                        drawingPart.DeletePart(oldPart)
                        ' add the ImagePart
                        Dim newPart As ImagePart = drawingPart.AddImagePart(ImagePartType.Png, id)
                        ' replace image
                        Dim replacement As String = imagePath
                        Using stream As New FileStream(replacement, FileMode.Open)
                            ' feed data to the newPart
                            newPart.FeedData(stream)
                        End Using
                    End If
                Next
                ' save xml document to the stream
                doc.Save(drawingPart.GetStream(FileMode.Create))
            End If
        Catch ex As Exception

        End Try

    End Sub

When I examine the result of this I still get the same error when I'm opening the file, but the correct image is now shown on the inserted sheets.

I believe there must be some other relation that is left in the workbook, but I have not been able to locate it.

Can someone help with sample code in VB or C# I would be much obliged?


Best Regards Peter Karlström Midrange AB, Sweden

Remove Empty TextBoxContent or TextBox From .docx file Using OpenXML

$
0
0

Hi, 

I am new to open XML. I want to remove all empty TextBoxContent or TextBox From .docx file Using OpenXML?

How i am going achieve this?

Thanks

Looking for examples using OpenXML SDK

$
0
0

I am looking for examples of using the OpenXML SDK such as

  • Opening a DOCX or xlsx or xlsm
  • Select specific sub xml files in a docx, xlsx, or xlsm
  • Search for and parse specific node  in the sub xml file
  • What is best tool for this? Something like xPath or other

Thank you,

Jim


Jim

How can I Present WordprocessingML document?

$
0
0

Hi, 

In my project I need to present a read-only word document given to me in WordprocessingML format.

Currently I convert the WordML to HTML using XSLT but the resulting document is far from perfect.

Is there is something except MS Word COM component to present WordML?

I'm open to all .NET technologies, including Orcas.

 

Hope it's the right forum,

Thanks.

Delete Attributes

$
0
0

Posting here on the suggestion in another group to post in a more XML oriented group. Hope I'm in or at least closer to the right place.

I am attempting, perhaps fruitlessly, to develop a rudimentary custom change event for a Word rich text content control. I am not a true programmer and just dabble with VBA.  However, I have working custom change event which detects changes in "text" and was hoping to expand it to detect any change.

My thought was to set a string variable = to the WordOpenXML value in the control and then monitor the WordOpenXML and trigger a change event when it changes from the reference string value.  I learned right away that the value of the WordOpenXML is huge and contains attributes (rsid values) that can change when the XML is querried.

What I have done since is to narrow the XML string down to a much smaller chunk.  What I am now trying to do is remove any attribute that has a basename of "rsidRPr" I found on a google search a method  .removeAttribute, but I can't make it work.

For this code to work you need a blank Word document with a single richtext control containing a small bit of text.

Thanks.

Sub ScratchMacro()
Dim oXDoc As New MSXML2.DOMDocument
Dim oNode As MSXML2.IXMLDOMNode
Dim oNode2 As MSXML2.IXMLDOMNode
Dim oNode3 As MSXML2.IXMLDOMNode
Dim oAttr As MSXML2.IXMLDOMAttribute
oXDoc.LoadXML (ActiveDocument.ContentControls(1).Range.WordOpenXML)
oXDoc.setProperty "SelectionLanguage", "XPath"
oXDoc.setProperty "SelectionNamespaces", _"xmlns:pkg='http://schemas.microsoft.com/office/2006/xmlPackage'" & _" xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'"
'Set a = oXDoc.SelectNodes("/pkg:package[1]/pkg:part[3]/pkg:xmlData[1]/w:document[1]/w:body[1]/w:p[1]")
Set oNode = oXDoc.SelectSingleNode("/pkg:package[1]/pkg:part[3]/pkg:xmlData[1]/w:document[1]/w:body[1]/w:p[1]")
For Each oNode2 In oNode.ChildNodes
  For Each oNode3 In oNode2.ChildNodes
    For Each oAttr In oNode2.Attributes
      If oAttr.BaseName = "rsidRPr" Then
        oNode2.removeAttribute (oAttr.BaseName)
      End If
    Next
  Next oNode3
Next oNode2
ActiveDocument.Range.InsertAfter vbCr & oNode.XML
End Sub


Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm


MapId not found in CustomXmlMappingsPart

$
0
0

Hi,

I created an excel file. Added an xml data from web source. Excel asked me to create a schema for the xml, I followed and imported the table from xml web source. Whenever I refresh the connection, I get the latest data from web on Table on the sheet.

Now, I opened this excel file with Productivity Tool. Generated code for the same. Used the code as is to generate an excel file.

I was expecting the same behavior by generated excel. However, I do not get it. It does not show any error but refresh does not work.

If I see the validation of the generated file on Productivity Tool, it says "'xmlcolumnpr@mapid' does not exist in part CustomXmlMappingsPart" for all columns that are generated.

Am I missing something? Adding the error screen.

I need to create an excel using OpenXML SDK which will be refreshable. This will use Web Query to fetch XML data from web.

Thanks,

Tushar

Mail merge problem using open xml,.Net and Word 2007

$
0
0

I am trying to generate mail merge document using open xml. I can generate the document but not all merge fields are processed.

When I loop through merge fields only 8 out of 10 merge fields are processed. The last two merge fields («month» and «effdate») seem not to be recognized as SimpleField
                  For Each objField As SimpleField In objMainDoc.Descendants(Of SimpleField)()
                                ''
                   Next

I attached the xml of the Word document.

- <w:body xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
- <w:p w:rsidR="00E25A17" w:rsidP="00B77522" w:rsidRDefault="001E6954">
- <w:pPr>
  <w:jc w:val="center" />
  </w:pPr>
- <w:fldSimple w:instr="MERGEFIELD date \m \* MERGEFORMAT">
- <w:r w:rsidR="00B77522">
- <w:rPr>
  <w:noProof />
  </w:rPr>
  <w:t>«date»</w:t>
  </w:r>
  </w:fldSimple>
  </w:p>
  <w:p w:rsidR="00E25A17" w:rsidRDefault="00E25A17" />
  <w:p w:rsidR="00E25A17" w:rsidRDefault="00E25A17" />
- <w:p w:rsidR="00B77522" w:rsidRDefault="001E6954">
- <w:fldSimple w:instr="MERGEFIELD name \m \* MERGEFORMAT">
- <w:r w:rsidR="00B77522">
- <w:rPr>
  <w:noProof />
  </w:rPr>
  <w:t>«name»</w:t>
  </w:r>
  </w:fldSimple>
  </w:p>
- <w:p w:rsidR="00B77522" w:rsidRDefault="001E6954">
- <w:fldSimple w:instr="MERGEFIELD memadln1 \m \* MERGEFORMAT">
- <w:r w:rsidR="00B77522">
- <w:rPr>
  <w:noProof />
  </w:rPr>
  <w:t>«memadln1»</w:t>
  </w:r>
  </w:fldSimple>
  </w:p>
- <w:p w:rsidR="00B77522" w:rsidRDefault="001E6954">
- <w:fldSimple w:instr="MERGEFIELD memadln2 \m \* MERGEFORMAT">
- <w:r w:rsidR="00B77522">
- <w:rPr>
  <w:noProof />
  </w:rPr>
  <w:t>«memadln2»</w:t>
  </w:r>
  </w:fldSimple>
  </w:p>
- <w:p w:rsidR="00B77522" w:rsidRDefault="001E6954">
- <w:fldSimple w:instr="MERGEFIELD memadln3 \m \* MERGEFORMAT">
- <w:r w:rsidR="00B77522">
- <w:rPr>
  <w:noProof />
  </w:rPr>
  <w:t>«memadln3»</w:t>
  </w:r>
  </w:fldSimple>
  </w:p>
- <w:p w:rsidR="00E25A17" w:rsidP="00D11496" w:rsidRDefault="001E6954">
- <w:pPr>
- <w:tabs>
  <w:tab w:val="left" w:pos="1635" />
  </w:tabs>
  </w:pPr>
- <w:fldSimple w:instr="MERGEFIELD memadln4 \m \* MERGEFORMAT">
- <w:r w:rsidR="00B77522">
- <w:rPr>
  <w:noProof />
  </w:rPr>
  <w:t>«memadln4»</w:t>
  </w:r>
  </w:fldSimple>
  </w:p>
- <w:p w:rsidR="00926FE1" w:rsidP="00D11496" w:rsidRDefault="00926FE1">
- <w:pPr>
- <w:tabs>
  <w:tab w:val="left" w:pos="1635" />
  </w:tabs>
  </w:pPr>
  </w:p>
- <w:p w:rsidR="00E25A17" w:rsidRDefault="00E25A17">
- <w:r>
  <w:t xml:space="preserve">Dear</w:t>
  </w:r>
- <w:fldSimple w:instr="MERGEFIELD dearname \m \* MERGEFORMAT">
- <w:r w:rsidR="00B77522">
- <w:rPr>
  <w:noProof />
  </w:rPr>
  <w:t>«dearname»</w:t>
  </w:r>
  </w:fldSimple>
  </w:p>
  <w:p w:rsidR="00E25A17" w:rsidRDefault="00E25A17" />
- <w:p w:rsidR="00E25A17" w:rsidP="0047518D" w:rsidRDefault="00D11496">
- <w:r>
  <w:t xml:space="preserve">The Fund records indicate that you worked</w:t>
  </w:r>
- <w:fldSimple w:instr="MERGEFIELD wkhours \m \* MERGEFORMAT">
- <w:r w:rsidR="00B77522">
- <w:rPr>
  <w:noProof />
  </w:rPr>
  <w:t>«wkhours»</w:t>
  </w:r>
  </w:fldSimple>
- <w:r>
  <w:t xml:space="preserve">contributing hours during</w:t>
  </w:r>
- <w:fldSimple w:instr="MERGEFIELD month \m \* MERGEFORMAT">
- <w:r w:rsidR="00B77522">
- <w:rPr>
  <w:noProof />
  </w:rPr>
  <w:t>«month»</w:t>
  </w:r>
  </w:fldSimple>
- <w:r>
  <w:t xml:space="preserve">Therefore, coverage is reinstated effective</w:t>
  </w:r>
- <w:r w:rsidR="00926FE1">
  <w:t xml:space="preserve"></w:t>
  </w:r>
- <w:fldSimple w:instr="MERGEFIELD effdate \m \* MERGEFORMAT">
- <w:r w:rsidR="009F5884">
- <w:rPr>
  <w:noProof />
  </w:rPr>
  <w:t>«effdate»</w:t>
  </w:r>
  </w:fldSimple>
- <w:r>

«date»

«name»

«memadln1»

«memadln2»

«memadln3»

«memadln4»

Dear «dearname»

The Fund records indicate that you worked«wkhours» contributing hours during «month» Therefore, coverage is reinstated effective «effdate». 

Thank you for any suggestion. 

 



Insert a Picture into the Picture/Image Content Control using Open XML SDK 2.0

$
0
0

I have created a word template as follows

Here PizzaPicture is a Picture Content Control, PizzaName is a Plain Text Content Control and PizzaDescription is a Rich Text Content Control

 

I am able to assign text to PizzaName and PizzaDescription Easily but not able to even locate the PizzaPicture. Here is my code

 

using (WordprocessingDocument document = WordprocessingDocument.Open(@".\test.docx", true)) {

                MainDocumentPart mainPart = document.MainDocumentPart;
                DocumentFormat.OpenXml.Wordprocessing.Text text = null;
                SdtContentBlock pizzaNameBlock = null;
                SdtContentBlock pizzaDescriptionBlock = null;//SdtContentBlock pizzaPictureBlock = null;  

                List<SdtBlock> sdtList = mainPart.Document.Descendants<SdtBlock>().ToList();foreach (SdtBlock sdt in sdtList)
                {
                    Console.WriteLine(sdt.SdtProperties.GetFirstChild<Tag>().Val.Value);
                }

                SdtBlock s1 = mainPart.Document.Body.Descendants<SdtBlock>().Where(r => r.SdtProperties.GetFirstChild<Tag>().Val == "PizzaName").Single();
                SdtBlock s2 = mainPart.Document.Body.Descendants<SdtBlock>().Where(r => r.SdtProperties.GetFirstChild<Tag>().Val == "PizzaDescription").Single();
                SdtBlock s3 = mainPart.Document.Body.Descendants<SdtBlock>().FirstOrDefault(r =>
                {
                    SdtProperties p = r.Elements<SdtProperties>().FirstOrDefault();if (p != null)
                    {
                        Console.WriteLine("P is not null");// Is it a picture content control?
                        SdtContentPicture pict =
                            p.Elements<SdtContentPicture>().FirstOrDefault();if (pict != null) Console.WriteLine("Pict is not null");// Get the alias.
                        SdtAlias a = p.Elements<SdtAlias>().FirstOrDefault();if (pict != null&& a.Val == "PizzaPicture")returntrue;
                    }returnfalse;
                });if (s3 == null) {
                    Console.Write(" s3 is Null");
                } else {
                    Console.WriteLine("s3 not null");
                }if (s1 != null) {
                    pizzaNameBlock = s1.Descendants<SdtContentBlock>().FirstOrDefault();
                    text = pizzaNameBlock.Descendants<DocumentFormat.OpenXml.Wordprocessing.Text>().FirstOrDefault();// here you can set the current time
                    text.Text = "Peperoni";
                    Console.WriteLine(text.Text);
                }string embed = null;if (s3 != null)
                {
                    Drawing dr = s3.Descendants<Drawing>().FirstOrDefault();if (dr != null)
                    {
                        Blip blip = dr.Descendants<Blip>().FirstOrDefault();if (blip != null)
                            embed = blip.Embed;
                    }
                }if (embed != null)
                {
                    IdPartPair idpp = document.MainDocumentPart.Parts
                        .Where(pa => pa.RelationshipId == embed).FirstOrDefault();if (idpp != null)
                    {
                        ImagePart ip = (ImagePart)idpp.OpenXmlPart;using (FileStream fileStream =
                            File.Open(@"c:\temp\pepperoni.jpg", FileMode.Open))
                            ip.FeedData(fileStream);
                    }
                }if (s2 != null) {
                    pizzaDescriptionBlock = s2.Descendants<SdtContentBlock>().FirstOrDefault();string altChunkId = "AltChunkId12345";
                    AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.Xhtml, altChunkId);
                    chunk.FeedData(File.Open(@".\html.txt", FileMode.Open));
                    AltChunk altChunk = new AltChunk();
                    altChunk.Id = altChunkId;////Replace content control with altChunk information                
                    OpenXmlElement parent = pizzaDescriptionBlock.Parent;
                    parent.InsertAfter(altChunk, pizzaDescriptionBlock);
                    pizzaDescriptionBlock.Remove();
                }

                mainPart.Document.Save();
                document.Close();
            }


Here the call mainPart.Document.Descendants<SdtBlock>().ToList(); returns me only 2 items PizzaName, PizzaDescription butno PizzaPicture.

 

Secondly the line   SdtContentPicture pict =  p.Elements<SdtContentPicture>().FirstOrDefault();returns NULL. So it seems that there is no element of type SdtContentPicture.

What am I doing wrong? I am pretty sure that I have put PizzaPicture as a Picture content control.

 

My objective is to locate this control in the document and then insert an image into it programmatically.

 

 


MSDNStudent Knows not much!

How to extarct the page number of a founded word with openxml and c#

$
0
0

Hello,

There are some example in web for finding a word in Word Documens. But how to find the page number of each founded word?

Thank you,

Mohsen


Applying or removing the Hyperlink style by searching and replacing the underlying XML in the document

$
0
0

Search
<w:rStyle w:val="Hyperlink"/></w:rPr><w:t>http://www.bbc.co.uk</w:t></w:r></w:hyperlink>
Replace
http://www.bbc.co.uk

Hello,

I am trying to search and replace inside the XML within a Word .docx file. I am trying to eliminate the hyperlink style but retain the website address within the hyperlink. From what I can tell, the above search string specifies the start and end hyperlink tags, so I was trying replace the above search string with simply the replacement website address. When I ran this replacement, it corrupted the Word document. I then tried to remove retain various tags such as </w:rPr> or <w:t> or </w:t> or </w:r>, within the replacement string. Each of these attempts also corrupted the document.
Does anyone have a clue as to what I am doing wrong
(I need to run this replacement over many documents, so I cannot use the Word user interface.)

Many thanks.
Keith


R K Howard

Open XML

$
0
0

In the example XML below, where (how) would I find the font properties for the text element within the run? Specifically, where (how) can I find the data which tells me to apply Calibri Light font, font size 44. to the run?

<p:sp xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"><p:nvSpPr><p:cNvPr id="2" name="Title 1" /><p:cNvSpPr><a:spLocks noGrp="1" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" /></p:cNvSpPr><p:nvPr><p:ph type="title" /></p:nvPr></p:nvSpPr><p:spPr /><p:txBody><a:bodyPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" /><a:lstStyle xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" /><a:p xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><a:r><a:rPr lang="en-US" dirty="0" smtClean="0" /><a:t>Slide 4 title – Calibri Light (Heading) 44 font </a:t></a:r><a:endParaRPr lang="en-US" dirty="0" /></a:p></p:txBody></p:sp>

Any assistance appreciated.

Thanks.

Can't install -- Open XML SDK 2.5 is not supported on .NET Framework Version 4.5 - is there a workaround?

$
0
0

My corporate client provided me a high powered laptop (with secure network access) for development purposes.   When I attempt to install the OpenXMLSDKV25.msi it reports "You should have .NET Framework 4.0 installed before you setup Open XML SDK 2.5..."

Visual Studio shows that my laptop has Microsoft .NET Framework Version 4.5.50709 installed

Is there a work-around so that I can get it installed? 


MCAD.NET C# - http://www.Global-webnet.com/Blog


Change programaticaly the datasource on Excel2013

$
0
0

Hi!

I have create a Excel2013 file with enabled PowerPivot features.

The datasource of the Excel reads data from SharePoint server Lists.

The problem is that I need a way to programmatically change the data source of the file . (Specifically I want to change the server name on the DataSource)

How can I achieve that ?

StyleSheet in OpenXML

$
0
0

Hi there, I don't know if it is possible but

Given an existing .xlsx Can I use it as a template file and apply its stylesheet to a new .xlsx file? Maybe using the indexStyle, I don't know.

I hope you can help me with this question.

Thanks in advance.

Eduardo

OpenXML - Problem showing carriage returns in content controls

$
0
0

Hi, I have the below function that populates my content controls. I am having a problem with showing carriage returns though. They show fine in my textbox on my .aspx page but are not when use the code below to add them to the associated content control.

Protected Sub PopulateContentControls(ByVal dictReplacements As Dictionary(Of String, String))
        Dim originalTemplate As String = ConfigurationManager.AppSettings("WordTemplateLocation") & GetTemplateFilename()
        Dim username As String = Utilities.GetUsername()
        Dim newFileCreated As String = ConfigurationManager.AppSettings("TempWordFileLocation") & username & ".docx"
        File.Copy(originalTemplate, newFileCreated, True)

        Using document As WordprocessingDocument = WordprocessingDocument.Open(newFileCreated, True)
            Dim mainPart As MainDocumentPart = document.MainDocumentPart
            Dim body As Body = mainPart.Document.Body

            'If custom xml content exists, delete it first
            mainPart.DeleteParts(Of CustomXmlPart)(mainPart.CustomXmlParts)

            For Each sdt As SdtElement In body.Descendants(Of SdtElement)().ToList()
                Dim [alias] As SdtAlias = sdt.Descendants(Of SdtAlias)().FirstOrDefault()
                If [alias] IsNot Nothing Then

                    If sdt.ToString() = "DocumentFormat.OpenXml.Wordprocessing.SdtRun" Then
                        Dim xStdRun As SdtRun = DirectCast(sdt, SdtRun)
                        Dim xStdContentRun As SdtContentRun = xStdRun.Descendants(Of SdtContentRun)().FirstOrDefault()
                        Dim xRun As Run = xStdContentRun.Descendants(Of Run)().FirstOrDefault()
                        Dim xText As Text = xRun.Descendants(Of Text)().FirstOrDefault()
                        Dim sdtTitle As String = [alias].Val.Value
                        xText.Text = dictReplacements.Item(sdtTitle)

                    ElseIf sdt.ToString() = "DocumentFormat.OpenXml.Wordprocessing.SdtBlock" Then
                        Dim xStdBlock As SdtBlock = DirectCast(sdt, SdtBlock)
                        Dim xStdContentBlock As SdtContentBlock = xStdBlock.Descendants(Of SdtContentBlock)().FirstOrDefault()
                        Dim xRun As Run = xStdContentBlock.Descendants(Of Run)().FirstOrDefault()
                        Dim xText As Text = xStdContentBlock.Descendants(Of Text)().FirstOrDefault()
                        Dim sdtTitle As String = [alias].Val.Value
                        xText.Text = dictReplacements.Item(sdtTitle)

                    End If

                End If
            Next

            mainPart.Document.Save()
            document.Close()

        End Using
    End Sub

I'm very new to OpenXML, is there a replace statement I can use to show the carriage returns in my Word file? I have tried plain text controls with the carriage return option ticked. I have also tried rich text but no luck on either unfortunately.

I have tried the following with Replace Chr(10) statements with no success:

xText.Text = xText.Text.Replace(Chr(10), "\r\n")

xText.Text = xText.Text.Replace(Chr(10), "<p />")

xText.Text = xText.Text.Replace(Chr(10), vbLf)

xText.Text = xText.Text.Replace(Chr(10), Environment.NewLine)

EDIT - Can this please be moved to the OpenXML forum? I've only just noticed it sorry.



What is needed to set up the runtime for using code created with the open XML SDK

$
0
0

My Systems Admin needs to know what needs to be installed on the server to support code designed with the Open XML SDK.

HELP NEEDED! : Worksheet with multiple TableDefinitionParts causes issue due to Uri naming.

$
0
0

Creating a TableDefinitionPart with TableDefinitionPart tdp = worksheetpart.AddNewPart<TableDefinitionPart>() causes tables to be added following the naming convention (table.xml, table2.xml, ..., tablea.xml, etc.).  These Uri paths are created with hex values, though the id in the actual table xml is UInt32 (1,2,3,...,etc.).  It appears if I go over 12 tables then something with the name of the part and ids gets confused inside of Excel.  So two questions:  Is there any way possible to control the name (Uri) of the part when it is created(added).  If not, is there anyway to control how the SDK is choosing to number the tables (i.e. don't use hex).

If none of those options is viable, can anyone think of any other workaround?

Thanks in advance.

Viewing all 1288 articles
Browse latest View live


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