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

SpreadsheetML - Determining pages

$
0
0

So I'm researching setting up a VSTO Excel Addin like a Word one I have.  I'll be sending the spreadsheet to a web service that extracts the text "in order" using OOXML apis and does some processing.  For Excel I want the server to extract the text in page order and extract the proper header and footer with each page.

I know about the manual page breaks (columnBreaks and rowBreaks) and I can handle those.  But I'm unsure how to handle natural page breaks caused by exceeding page boundaries like you see in the Page Layout view in Excel.  It seems like I could the paper size, margins, default column widths and row heights, and overridden column/row sizes to figure it all out.  But I'm stil unsure on how to glue it together (like how to get the column width in inches or something usable).

Anyone know of any examples of something like this?  Or a better way to go about this problem?


How to preserve tablestyle when StylesDefinition from a template is applied

$
0
0

Hi

In our project we are creating documents from a predefined text-document on which we apply headers, footers, margins, themes and styles from a Word template (dotx).

The solution has worked fine as a webservice in every case so far, but we are now experiencing problems regarding table styles.

If the predefined text has a tablestyle set, for instance "Medium dark-shadow1-color 1" (translated from swedish), which also exists in the template and is a part af the standard Office Theme, the document looses the style and the table ends up as plain white one.

We apply styles from the template with the following code:

   Friend Sub WDCopyStyles(ByVal fromdoc As String, ByVal toDoc As String)

        Dim wordDoc1 As WordprocessingDocument = WordprocessingDocument.Open(fromdoc, False)
        Dim wordDoc2 As WordprocessingDocument = WordprocessingDocument.Open(toDoc, True)

        Dim styleDefPart = wordDoc1.MainDocumentPart.GetPartsOfType(Of StyleDefinitionsPart).FirstOrDefault()
        Dim styleDefPart2 = wordDoc2.MainDocumentPart.GetPartsOfType(Of StyleDefinitionsPart).FirstOrDefault()
        Using wordDoc2
            If styleDefPart2 Is Nothing Then
                wordDoc2.MainDocumentPart.AddPart(Of StyleDefinitionsPart)(styleDefPart)
            Else
                wordDoc2.MainDocumentPart.DeletePart(styleDefPart2)
                wordDoc2.MainDocumentPart.AddPart(Of StyleDefinitionsPart)(styleDefPart)
            End If

        End Using

        wordDoc1.Close()

    End Sub

What am I missing?

Thanks in advance


Best Regards Peter Karlström Midrange AB, Sweden

Lock content after programmatically replaced Content Control with content

$
0
0

Hi,

I have developed an application that does a lot of merging of documents using OpenXML, AltChunk and Content Controls. My Content Controls have the "Remove content control when contents are edited" checkbox checked.

What I want to do next, is to lock the content that has replaced a Content Control. In other words, when the final document is ready, users will not be able to edit the content.
Important note: I don't want to lock the whole document, just parts of it (where selected Content Controls are replaced with content).

Is this possible?

I have tried checking the "Contents cannot be edited" property on the Content Controls, both with and without the "Remove content control when contents are edited" checkbox checked. Doesn't work.

Is there a way to do this using code?

Thanks!

Edit: Here's some of my code:

using (MemoryStream mem = new MemoryStream())
{
mem.Write(byteArray, 0, (int) byteArray.Length);
mem.Seek(0, SeekOrigin.Begin);
chunk.FeedData(mem);
}

Word.AltChunk altChunk = new Word.AltChunk();
altChunk.Id = altChunkId;

OpenXmlElement parent = sdt.Parent;
parent.InsertAfter(altChunk, sdt);
sdt.Remove();


Edit 2:
I guess I now realize that my code doesn't really make use of the Content Controls other than using them as "bookmarks". What I need is to insert my content in the actual Content Controls.

The content I'm trying to insert is content from other Word documents.

Can anyone please advise me on how to do this?

Can we remove remove specific custom properties from a Word Document using OpenXML?

$
0
0

I have 10 custom properties, in my word document. From what I can understand these custom properties are saved in customXML part in the word document structure. What I need to do is, remove 1 property out of the 10 from inside the custom xml part of the document. Is there a way to do this with OpenXML?

Currently I have been able to retrieve the values from the Item2.xml file in the customXml folder of my document package (renaming the .docx document file to .zip)

Whenever I try to update the xml contents, the document properties get corrupted. Any help would be appreciated

How to save Word as PDF using Open XML SDK 2.0

$
0
0

How do we use Open XML SDK 2.0 to save word files as a PDF? 


Thomas Abruzzo thomas@tampsystems.com

Inserting image with OpenXml 2.0, Error with contents in Word 2007

How to UpdateStyles using OpenXML

$
0
0

Hi

In Word automation you can use the command ActiveDocument.UpdateStyles to make the document visually apply format specifications from the attached template.

Is there any known way of doing this using Open XML SDK?

Thanks in advance


Best Regards Peter Karlström Midrange AB, Sweden

How to resolve a date format excel cell value

$
0
0
Hi

I'm trying to read a date format excel cell, but the result of this reading is different that the result i expected. For example, if the cell value is 11-dec-2009 the system returns 40158. How could i retrieve the correct value? I checked the datetype returned by openxml but it's null.

Any help will be appreciated

Thanks

OpenXML 2.5: Images added to the document don't display

$
0
0
Did you solve this issue?

I'm trying to add an image to an existing Word 2010 document using OpenXML SDK 2.5. But when I add the image the image does not get embedded. When I open the document, the image shows the placeholder with a red cross (as if the image cannot be found). I'm using the following code:

string mimetype = String.Empty;
// :
//Find mime type of the image here
// :
imagePart = wpd.MainDocumentPart.AddImagePart(mimetype);

using (FileStream stream = new FileStream(filename, FileMode.Open))
{
    image = new Bitmap(stream);
    cy = Convert.ToUInt32(image.PhysicalDimension.Height);
    cx = Convert.ToUInt32(image.PhysicalDimension.Width);
    imagePart.FeedData(stream);
    stream.Close();
 }
 Paragraph para = FindParagraphInAppendix(....); //Find the paragraph to add
 if (para != null)
    AddImageToParagraph(para, wpd.MainDocumentPart.GetIdOfPart(imagePart),txt, filename,cx,cy);
 else
      wpd.MainDocumentPart.Document.Body.Append(GetImageWithPara(wpd.MainDocumentPart.GetIdOfPart(imagePart), filename, cx, cy));
wpd.Package.CreateRelationship(imagePart.Uri, System.IO.Packaging.TargetMode.External,wpd.MainDocumentPart.GetIdOfPart(imagePart));
wpd.MainDocumentPart.Document.Save();

In the code for AddImageToParagraph I'm adding the image as follows:

Pic.BlipFill blipFill1 = new Pic.BlipFill();
A.Blip blip1 = new A.Blip() { Embed = relationshipid,
                             CompressionState = A.BlipCompressionValues.Print };
A.BlipExtensionList blipExtensionList1 = new A.BlipExtensionList();

When I open the file generated using Winzip, the document.xml.rels file does not contain a relationship ID associated with the embedded image.

When I open the using OpenXML Productivity tool and validate the XML I get the error : "The relationship 'R75a8cc179...' referenced by attribute 'hxxp://schemas.openxmlformats..../relationships:embed' does not exist

But what strikes as odd is imagePart.AddImagePart is not creating a<Relationship> tag in the resulting document.xml.rels. Using a debugger and stepping through, I checked the output of wpd.GetReferenceRelationship(wpd.MainDocumentPart.GetIdOfPart(imagePart)) and it throws a System.Generic.Collections.KeyNotFoundException.

Can you help?


Unable to open .docx created with OpenXML SDK 2.5 in Word 2007

$
0
0

Hi,

I use OpenXML SDK 2.5 to open and modify a .dotx template in c# and save it in .docx format. Most of our machines are able to open the resulting file with no difficulty, but I've discovered that those of us using Word 2007 (not 2010 or 2013) get an error message when they try to open the .docx file: "The file ____.docx cannot be opened because there are problems with the contents." The details further specify: "The file is corrupt and cannot be opened. Location: Part: /word/settings.xml, Line: 1, Column: 2668"

Below is a portion of my code (the part responsible for creating the .docx file):

File.Copy(sourceFile, destinationFile, true);

using (WordprocessingDocument document = WordprocessingDocument.Open(destinationFile, true)){ 
  // Change the document type to Document   Documentdocument.ChangeDocumentType(DocumentFormat.OpenXml.WordprocessingDocumentType.Document);   // Get the MainPart of the document   MainDocumentPart mainPart = document.MainDocumentPart;   // Get the Document Settings Part   DocumentSettingsPart documentSettingPart1 = mainPart.DocumentSettingsPart;   // Create a new attachedTemplate and specify a relationship ID   AttachedTemplate attachedTemplate1 = new AttachedTemplate() { Id = "relationId1" };   // Append the attached template to the DocumentSettingsPart   documentSettingPart1.Settings.Append(attachedTemplate1);   // Add an ExternalRelationShip of type AttachedTemplate.   // Specify the path of template and the relationship   IDdocumentSettingPart1.AddExternalRelationship("http://schemas.openxmlformats.org/officeDocument/2006/relationships/attachedTemplate", new Uri(sourceFile, UriKind.Absolute), "relationId1");   // Get a list of bookmarks   IDictionary<String, BookmarkStart> bookmarkMap = new Dictionary<String, BookmarkStart>();   foreach (BookmarkStart bookmarkStart in mainPart.RootElement.Descendants<BookmarkStart>())   {      bookmarkMap[bookmarkStart.Name] = bookmarkStart;   }   // Make changes to bookmarks   foreach (BookmarkStart bookmarkStart in bookmarkMap.Values)   {       if (bookmarkStart.Name == "WorkOrderNo")       {            Text text = new Text(WorkOrderNum);            FontSize WOFontSize = new FontSize();            WOFontSize.Val = "28";            Run run = new Run(new RunProperties(new Bold(), WOFontSize));            run.Append(text);            bookmarkStart.InsertAfterSelf(run);        }        else if (bookmarkStart.Name == "BillingCode")        {             Text text = new Text(BillingCode);             FontSize WOFontSize = new FontSize();             WOFontSize.Val = "28";             Run run = new Run(new RunProperties(new Bold(), WOFontSize));             run.Append(text);             bookmarkStart.InsertAfterSelf(run);         }   }   // Save the document   mainPart.Document.Save();}

Word 2007 users are able to open the file if they choose "OK" on the prompt, and then "Yes" on the prompt reading: "Word found unreadable content in _____.docx. Do you want to recover the contents of this document? If you trust the source of this document, click Yes." While this is an acceptable short-term workaround, I'm hoping to come up with a solution to the problem. Any ideas?

(I can send/attach the .dotx and .docx files if desired; I just couldn't figure out how to attach them to this post)

Thanks,

- Jim


Open xml pakage editor

$
0
0
is there an openxml pakage editor for visual studio 2012 pro

Use the Open XML Package Editor in Visual Studio 2012/2013

OpenXML Table Styles

$
0
0

This is my first attempt with OpenXML and creating styles in code.  I am trying to get the a style to do the following:

For a table,

1st row should be Bold, White, and background color of dark blue

all other rows should be (normal font), and a background color of white.

All rows should have a border on all four sides.

I've gotten the borders, and the conditional style for the 1st row, but I'm not seeing how to apply the background color to the rest of the document.  And yea, I do want a white background because there is a picture behind the table that is not white.

Here is my code, what am I doing wrong?

Style style1 = new Style( new TableProperties( new TableCellProperties() { Shading = new Shading() { Val = ShadingPatternValues.Clear, ThemeFill = ThemeColorValues.Background1,

Fill = "FFFFFF", Color = "auto" } }, new TableBorders( new TopBorder() { Val = BorderValues.Single }, new BottomBorder() { Val = BorderValues.Single }, new LeftBorder() { Val = BorderValues.Single }, new RightBorder() { Val = BorderValues.Single }, new InsideHorizontalBorder() { Val = BorderValues.Single }, new InsideVerticalBorder() { Val = BorderValues.Single })), new TableStyleProperties( new TableRowProperties( new ParagraphProperties( new RunProperties() { Bold = new Bold() { Val = true }, Color = new Color() { Val = "FFFFFF", ThemeColor = ThemeColorValues.Background1 }, }), new CantSplit(), new TableHeader() { Val = OnOffOnlyValues.On }, new TableCellProperties() { Shading = new Shading() { Val = ShadingPatternValues.Clear, ThemeFill = ThemeColorValues.Text2, Fill = "1F497D", Color = "auto" } } ) ) { Type = TableStyleOverrideValues.FirstRow } ) { Default = false, Type = StyleValues.Table, StyleId = "TableStyle1", StyleName = new StyleName() { Val = "TableStyle1" }, UIPriority = new UIPriority() { Val = 1 } };



jhoop

What forum?

$
0
0
This is the forum for editing the open XML packages for excel documents but what forum would I write to if I wanted to add actual functionality to the excel program itself.

How to find the type of sdtBlock: RichText, PlainText or Picture

$
0
0

There are several Rich Text Content Controls and Plain Text Content Controls in my Word document.

These Content Controls are defined in document.xml as sdtBlocks.

How using Open XML SDK 2.0 (I mean using C# code) to find out what asdtBlock presents: Rich or Plain Text Content Control.

Thanks.


Lock cells in Spreadsheet

$
0
0

I want to lock some cells in spreadsheet programatically.

The document is stored in Sharepoint library.

Is there any way to lock the cells?

I have designed a web part.

I mean, end user enter the cells which needs to be locked in a textbox, and clicks a button.

On button click event, i need to lock the entered cells in a document which is in a library.

How to lock the cell using spreadsheetdocumentclass?


Open XML sdk for making font bold

$
0
0

Hi,

I am using OpenXML SDK for exporting data into a an excelsheet using C#.

I want header row in excel to be in bold.

Please give me code for the same.

Thanks in advance

PAGEREF for bookmarks always 1 when opening a document

$
0
0

I'm trying to create a simple toc, but I don't want to use at all the built in TOC.

First I mark entries with bookmarks with similar fragments:

<w:bookmarkStart w:name="B1" w:id="1" /><w:r><w:t>Some text</w:t></w:r><w:bookmarkEnd w:id="1" />

Now I use the PAGEREF field in my toc, to get the page number of the bookmark, like this:

<w:r><w:fldChar w:fldCharType="begin" w:dirty="true" /></w:r><w:r><w:instrText xml:space="preserve"> PAGEREF B1 \h </w:instrText></w:r><w:r><w:fldChar w:fldCharType="separate" w:dirty="true" /></w:r><w:r><w:rPr><w:noProof /></w:rPr><w:t>?</w:t></w:r><w:r><w:fldChar w:fldCharType="end" w:dirty="true" /></w:r>

I also add correctly UpdateFieldsOnOpen in the settings. My goal of course that word updates the pageref fields when opening the document.

When opening the document, I get the warning messagebox, so the updatefieldsonopen really kicks in, but all pageref fields value resolved to "1".

So in my toc all entry has "1" as the page number.

(Switching the print preview refresh all page number correctly, so the bookmarks works fine, problem is only when opening the document.)


openxml sdk and openoffice write

$
0
0

Hi all,

  Do you know if and how is possible to use OpenXml sdk to read and write files compatible with openoffice write?

Thanks,

  Luca

MERGEFIELD Field Code Issues

$
0
0
We have created a document template (*.doct) which outlines several MERGEFIELD's which were created using the wizard within Word 2013.
The purpose of the application is that we are trying to create invoices by passing data to a document template where it will use the MERGEFIELD's to populate the invoice with the wanted data.
We are basing our logic from this sample:
http://www.jarredcapellman.com/2012/10/22/c-openxml-mail-merge-complete-example/
 
When doing a lookup of the MERGEFIELD's being used, we are receiving nonsensical field codes (e.g. The field codes are being cut into two lines. The field codes that we are using do not include any white space)
It appears that the parsing is being done incorrectly.
If anyone can make any sense of this that would be great.


Viewing all 1288 articles
Browse latest View live


Latest Images

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