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

create word document from template using openxml sharepoint

$
0
0

Hi All,

I want to create a word document from template using openxml.

Template document is saved in a Document Library Sharepoiint.

Please let me know how to achieve this.


Do you need to convert OpenXML to PDF, XPS or DOC?

$
0
0
I have searched this forum and found there are several requests about how to convert OpenXML documents to PDF, XPS and DOC. Some of the replies suggest using third party libraries, such as Aspose.Words. But these replies also often mention that these components are expensive.

Here is the bit, I am a project manager of Aspose.Words and I would like to see how we can serve the needs of the OpenXML Format SDK users to convert DOCX to PDF, XPS and DOC.

Aspose.Words for .NET is a document processing library that offers features in four areas: conversion, programming, reporting and rendering. It is an established, feature rich and reliable product and yes, it is priced accordingly, it starts from $899.

What I am thinking of doing is making a special version of our product Aspose.Words for OpenXML Format SDK that will be cut down to only support features that the OpenXML SDK users most often require. At this stage it looks like you need conversion of DOCX to PDF, XPS and DOC. These all are supported in Aspose.Words. What do you think about such a product and how much do you think it should cost not to be labeled as "too expensive"? 
 
Regards,
Roman Korchagin

Is Open XML SDK 2.5 supported on Windows 7 64 bit OS?

$
0
0

 Prior to installing and using Open XML SDK 2.5 in our work environment I need to provide evidence that it's supported on Windows 7, 64 bit OS.

Is someone able to confirm that it is supported and does work? the download site states it's compatible with Windows 7, but doesn't mention Windows 7 64 bit. There are very strict rules enforced and I need to satisfy the compatibility section of the new app request.

Many thanks

AddAlternativeFormatImportPart error

$
0
0

I am facing strange error during

AddAlternativeFormatImportPart method .
THe calling is done as follows(I have tried two methods)

_resultWDoc.MainDocumentPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.WordprocessingML, altChunkId);

and

resultWDoc.MainDocumentPart.AddAlternativeFormatImportPart                                     ("application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml", altChunkId);

error I get is, everytime with different hexadecimal character, the following one

The '͈' character, hexadecimal value 0x348, cannot be included in a name.

Filter on existing excel using openXML in C#

$
0
0

Hi,

Please explain, how to apply filter to an existing excel for the cell reference A2:AG700.

 

thanks,

Elangovan P

Unable to add an Image to a powerpoint presentation.

$
0
0

Hi,

I am using the following code to add a new slide to a ppt file and add an image. I am using Open XML 2.5 SDK.

A new slide is getting added but not the image. Is there anything wrong in this code?

int position = 1;
            using (PresentationDocument presentationDocument = PresentationDocument.Open("c.pptx", true))
            {

                PresentationPart presentationPart = presentationDocument.PresentationPart;

                Slide slide = new Slide(new CommonSlideData(new ShapeTree()));
   
                NonVisualGroupShapeProperties nonVisualProperties = slide.CommonSlideData.ShapeTree.AppendChild(new NonVisualGroupShapeProperties());
                nonVisualProperties.NonVisualDrawingProperties = new NonVisualDrawingProperties() { Id = 1, Name = "" };
                nonVisualProperties.NonVisualGroupShapeDrawingProperties = new NonVisualGroupShapeDrawingProperties();
                nonVisualProperties.ApplicationNonVisualDrawingProperties = new ApplicationNonVisualDrawingProperties();

                // Specify the group shape properties of the new slide.
                slide.CommonSlideData.ShapeTree.AppendChild(new GroupShapeProperties());

                // Create the slide part for the new slide.
                SlidePart slidePart = presentationPart.AddNewPart<SlidePart>();


                // Save the new slide part.
                slide.Save(slidePart);
                string imgId = "rId" + new Random().Next(2000).ToString();
                ImagePart imagePart = slidePart.AddImagePart(ImagePartType.Png, imgId); 

                using (FileStream stream = new FileStream("a.png", FileMode.Open))
                {
                    stream.Position = 0;
                    imagePart.FeedData(stream);
                }

                

                slide.Save(slidePart);
                



                

                // Modify the slide ID list in the presentation part.
                // The slide ID list should not be null.
                SlideIdList slideIdList = presentationPart.Presentation.SlideIdList;

                // Find the highest slide ID in the current list.
                uint maxSlideId = 1;
                SlideId prevSlideId = null;

                foreach (SlideId slideId in slideIdList.ChildElements)
                {
                    if (slideId.Id > maxSlideId)
                    {
                        maxSlideId = slideId.Id;
                    }

                    position--;
                    if (position == 0)
                    {
                        prevSlideId = slideId;
                    }

                }

                maxSlideId++;

                // Get the ID of the previous slide.
                SlidePart lastSlidePart;

                if (prevSlideId != null)
                {
                    lastSlidePart = (SlidePart)presentationPart.GetPartById(prevSlideId.RelationshipId);
                }
                else
                {
                    lastSlidePart = (SlidePart)presentationPart.GetPartById(((SlideId)(slideIdList.ChildElements[0])).RelationshipId);
                }


                // Use the same slide layout as that of the previous slide.
                if (null != lastSlidePart.SlideLayoutPart)
                {
                    slidePart.AddPart(lastSlidePart.SlideLayoutPart);
                }

                // Insert the new slide into the slide list after the previous slide.
                SlideId newSlideId = slideIdList.InsertAfter(new SlideId(), prevSlideId);
                newSlideId.Id = maxSlideId;
                newSlideId.RelationshipId = presentationPart.GetIdOfPart(slidePart);

                // Save the modified prsentation.
                presentationPart.Presentation.Save();

Thanks in advance.

Line Chart in powerpoint using Open XML SDK 2.5

$
0
0

Hi,

I want to add a new slide to an existing powerpoint file and add a new line chart.

The number of series and data points and labels will be dynamic. How to achieve it using Open XML SDK? I couldn't find any good documentation on charts.

Thanks

Word 2010 w:fldSimple keeps being replaced with w:instrText when I save document DOCX

$
0
0

My Word 2010 document's mergefield codes (w:fldSimple) keep getting replaced with w:instrText.

I have one field in particular that will not change no matter what I do. The field name is a 26 character field. If I delete this field and add it again, it changes ALL the mergefields to w:instrText when it is saved. When I do a right click and update field command on each mergefield, they all change to w:fldSimple except for this problem field when it is saved. The problem field stays as w:instrText.

Are there any quirks with mergefields? If so, how do I work around them?

Thanks!


OpenXmlReader SAX Reader appears to slow down as it gradually reads large file

$
0
0

Hi guys,

I am using the OpenXMLReader to read a large Excel file with circa 500,000 rows of 20 columns. The file size is not that big (35MB).

I am reading through all elements and gathering together data from 512 rows at a time into a List. Then after processing the data the routine continues to process the rows and get the next batch. This continues until all batches have been read.

Memory consumption is absolutely fine and when the first few batches start to be read it is reasonably fast to read a batch of 512 rows (e.g. 100-200 milliseconds). As this continues this gradually slows down to seconds and then by the end of the file it's reached about 17 seconds to read 512 rows.

Is this expected behavior because it sure came as a surprise to me? With a streaming approach I would have expected that reading the last few batches would be roughly the same as reading the first few batches.

I have added detailed logging to make sure the time is spent in the function that is parsing the elements and there really is nothing complicated going on in there. Just reading the cell values and writing the strings into a List for each row.

Is there anything I need to do to prevent this behavior? All input very welcome.

Kind regards,.

Ian

 

AddAltChunkHTML to DOCX Inserts BOM

$
0
0

I am inserting html text into a docx word document. All works okay except the end result docx file has a BOM at the beginning of the document.xml. I do not understand this although I suspect an encoding issue. Example code below. Would appreciate anyone's thoughts on this.

        void AddAltChunkHTML(MainDocumentPart mainPart, Word.SdtElement sdt, SPFile filename)
        {
            string altChunkId = "AltChunkId" + id;
            id++;
            // read insert data
            byte[] byteArray = filename.OpenBinary();

            AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.Xhtml, altChunkId);

            // load the insert data into the chunk
            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;
            //Replace content control with altChunk information

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

Replace HTML into Word docx Adds BOM to File

$
0
0
I am inserting html text into a docx word document. All works okay except the end result docx file has a BOM at the beginning of the document.xml. I do not understand this although I suspect an encoding issue. Example code below. Would appreciate anyone's thoughts on this.

        void AddAltChunkHTML(MainDocumentPart mainPart, Word.SdtElement sdt, SPFile filename)
        {
            string altChunkId = "AltChunkId" + id;
            id++;
            // read insert data
            byte[] byteArray = filename.OpenBinary();

            AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.Xhtml, altChunkId);

            // load the insert data into the chunk
            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;
            //Replace content control with altChunk information

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

Using OpenXML SDK via C++/CLI

$
0
0

I am trying to use the OpenXML SDK 2.5 via C++/CLI. Using the example code at the bottom of this MSDN page (http://msdn.microsoft.com/en-us/library/office/ff478153.aspx) works correctly when compiled with C# - I can open the created file successfully in Excel 2007.

The MSDN example code I translated to C++/CLI as follows:

void CreateSpreadsheetWorkbook(String^ filepath)
{
    // Create a spreadsheet document by supplying the filepath.
    // By default, AutoSave = true, Editable = true, and Type = xlsx.
    SpreadsheetDocument^ spreadsheetDocument = SpreadsheetDocument::Create(filepath, SpreadsheetDocumentType::Workbook);

    // Add a WorkbookPart to the document.
    WorkbookPart^ workbookpart = spreadsheetDocument->AddWorkbookPart();
    workbookpart->Workbook = gcnew Workbook();

    // Add a WorksheetPart to the WorkbookPart.
    WorksheetPart^ worksheetPart = workbookpart->AddNewPart<WorksheetPart^>();
    worksheetPart->Worksheet = gcnew Worksheet(gcnew SheetData());

    // Add Sheets to the Workbook.
    Sheets^ sheets = spreadsheetDocument->WorkbookPart->Workbook->AppendChild<Sheets^>(gcnew Sheets());

    // Append a new worksheet and associate it with the workbook.
    Sheet^ sheet = gcnew Sheet();
    sheet->Id = spreadsheetDocument->WorkbookPart->GetIdOfPart(worksheetPart);
    sheet->SheetId = 1;
    sheet->Name = L"mySheet";
    sheets->Append(sheet);

    workbookpart->Workbook->Save();

    // Close the document.
    spreadsheetDocument->Close();
}

The code compiles, but the file created is not complete. Excel 2007 complains about a corrupt file. Upon examining the contents of the xlsx file it looks like the details of the "mySheet"-sheet class does not get written to disk. What am I missing in the C++/CLI code that this is not working correctly?

I am using Visual Studio 2013 targeting .Net Framework 4.0.

openxml sdk2.0 The specified package is invalid. The main part is missing.

$
0
0
I try to open OpenXml with Open xml sdk 2.0 - but it failded. using (WordprocessingDocument myDoc = WordprocessingDocument.Open(fileName, true)) { } I have exception : A first chance exception of type 'DocumentFormat.OpenXml.Packaging.OpenXmlPackageException' occurred in DocumentFormat.OpenXml.dll Exception : The specified package is invalid. The main part is missing. why ? Everything happened correctly few months ago. But today is same problem , maybe it is the reason of windows or microsoft standard updating? If yes, what shoud I do?

Coloring of cells based on cell value using open XML in WPF

$
0
0

I have exported the data in excel using Open XML now I need to add color to the cells of few columns based on cell values.

Can you help me with the coloring part. My data is indata table.

 

(I am using WPF so from observable collection I took data in data table. There is no Gridview is involved in any case.

I want it through Open XML library.)

 

I was trying to do something like this

DoColourCell(excelWriter,table.Rows[numDataRows][i],null,table.Columns[i].ColumnName);

protected void DoColourCell(OpenXmlWriter excelWriter, object value1, uint? styleIndex, string value2)
{

cell.DataType = CellValues.Number;
cell.CellValue.Text = Convert.ToString(value1);
string s = cell.CellValue.Text;

if ((value2 ==”A” && s != null) || (value2 == “B” && s != null))
{
if (Convert.ToDouble(s) < 1.0)
{
…………
//I really don't how should I fill colours to the
cell based on cell value? what should I do in this part
I am completely new to open XML .

…………

}
}
if (styleIndex.HasValue)
{
cell.StyleIndex = styleIndex.Value;
}
excelWriter.WriteElement(cell);
}

how to transform field's text property

$
0
0

i using vsto in word addin develop, insert some field and applying some text to Field.Data property, then use openxml sdk to read it.

but the text in openxml have been transform, like below:

my original string is:

"b5688eda-0e9e-4ef7-9538-3a63c3a2076dx0|1.0.0"

but in openxml is:

"YgA1ADYAOAA4AGUAZABhAC0AMABlADkAZQAtADQAZQBmADcALQA5ADUAMwA4AC0AMwBhADYAMwBj\nADMAYQAyADAANwA2AGQAeAAwAHwAMQAuADAALgAwAA==\n"

my question is: how can i get the original string using openxml sdk?

thanks.


Coloring cells in excel sheet using openXML in C#

$
0
0

Hi,

Please explain, how to color the two different cells (C4,F6) with two different colors in the excel sheet using OpenXML in C#.

thanks,

Elangovan P

 

Relationship Transform Algorithm Issue

$
0
0

Hi,

I need some help in transforming and canonicalization of Office XML relationship file mentioned in title i.e. Document.xml.rels

I have seen that in the final signature file in OOXML Package, in which this document is referred i.e _xmlsignatures\sig1.xml

the document.xml.rels is mentioned like this:

<Reference URI="/word/_rels/document.xml.rels?ContentType=application/vnd.openxmlformats-package.relationships+xml"><Transforms><Transform Algorithm="http://schemas.openxmlformats.org/package/2006/RelationshipTransform"><mdssi:RelationshipReference SourceId="rId13"/><mdssi:RelationshipReference SourceId="rId18"/><mdssi:RelationshipReference SourceId="rId26"/><mdssi:RelationshipReference SourceId="rId39"/><mdssi:RelationshipReference SourceId="rId21"/><mdssi:RelationshipReference SourceId="rId34"/><mdssi:RelationshipReference SourceId="rId42"/><mdssi:RelationshipReference SourceId="rId47"/><mdssi:RelationshipReference SourceId="rId50"/><mdssi:RelationshipReference SourceId="rId55"/><mdssi:RelationshipReference SourceId="rId7"/><mdssi:RelationshipReference SourceId="rId12"/><mdssi:RelationshipReference SourceId="rId17"/><mdssi:RelationshipReference SourceId="rId25"/><mdssi:RelationshipReference SourceId="rId33"/><mdssi:RelationshipReference SourceId="rId38"/><mdssi:RelationshipReference SourceId="rId46"/><mdssi:RelationshipReference SourceId="rId16"/><mdssi:RelationshipReference SourceId="rId20"/><mdssi:RelationshipReference SourceId="rId29"/><mdssi:RelationshipReference SourceId="rId41"/><mdssi:RelationshipReference SourceId="rId54"/><mdssi:RelationshipReference SourceId="rId11"/><mdssi:RelationshipReference SourceId="rId24"/><mdssi:RelationshipReference SourceId="rId32"/><mdssi:RelationshipReference SourceId="rId37"/><mdssi:RelationshipReference SourceId="rId40"/><mdssi:RelationshipReference SourceId="rId45"/><mdssi:RelationshipReference SourceId="rId53"/><mdssi:RelationshipReference SourceId="rId15"/><mdssi:RelationshipReference SourceId="rId23"/><mdssi:RelationshipReference SourceId="rId28"/><mdssi:RelationshipReference SourceId="rId36"/><mdssi:RelationshipReference SourceId="rId49"/><mdssi:RelationshipReference SourceId="rId10"/><mdssi:RelationshipReference SourceId="rId19"/><mdssi:RelationshipReference SourceId="rId31"/><mdssi:RelationshipReference SourceId="rId44"/><mdssi:RelationshipReference SourceId="rId52"/><mdssi:RelationshipReference SourceId="rId9"/><mdssi:RelationshipReference SourceId="rId14"/><mdssi:RelationshipReference SourceId="rId22"/><mdssi:RelationshipReference SourceId="rId27"/><mdssi:RelationshipReference SourceId="rId30"/><mdssi:RelationshipReference SourceId="rId35"/><mdssi:RelationshipReference SourceId="rId43"/><mdssi:RelationshipReference SourceId="rId48"/><mdssi:RelationshipReference SourceId="rId8"/><mdssi:RelationshipReference SourceId="rId51"/></Transform><Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><DigestValue>OUXcZjyg0v3dbMCu6fSq/ws2VEc=</DigestValue></Reference></Manifest>

i need to know how Office has generated this output along with resulting hash i.e. "OUXcZjyg0v3dbMCu6fSq/ws2VEc=".

What i am doing is as follows:

1) Firstly removing all the nodes of Custom Xml from Document.xml.rels

2) Canonicalization of the resulting XML (using an sdk)

3) Generating Hash of the Resulting XML ( using C# library)

but i never get the same hash as mentioned above.

Please guide me what i am missing 

OR guide me how to transform n canonicalize the document to get the mentioned hash???




Embed Excel Sheet into Powerpoint Slide using Open XML SDK 2.5

$
0
0

Hello All,

I am trying to embed an excel worksheet into a powerpoint slide using the Open XML SDK 2.5.  I used the SDK Productivity tool and was able to reflect most of the code to make this work, but I've run into an issue regarding the height and width of the inserted object.

To duplicate the code, open a blank presentation, insert an object choose excel binary, 'from file' and pick an excel file (not linked).

This will:

  • Create an EmbeddedPackagePart tied to the SlidePart
  • Create a VmlDrawingPart tied to the SlidePart
  • Create an ImagePart tied to the VmlDrawingPart
  • Associate the ImagePart to the slide
  • Create and add a GraphicFrame to the shape tree
  • Create a Graphic and GraphicData with AlternateContent elements
  • Create OleObject and OleObjectEmbed elements associated to the alternate content elements
  • Create a Picture and BlipFill (and associated stuff) with the same rId as the ImagePart slide associate rId above

When I generate a new table picture from my table to use a preview, the dimensions are different than the reflected code, and so when I change the various Offset and Transform elements to match my calculated height and width (in EMUs), it breaks the embedding. It creates a Picture AND an ole frame.  However, if I don't touch the extents or offsets, it all works perfectly.

I suspect it is a relational thing where the Vml shape has to have the same exact height/width/top/left as the ole object, but I'm having trouble getting an accurate conversion from EMU (used by powerpoint) to points (used by vml)

I am at a complete loss on this and was hoping someone else who understands this more than I can help... any suggestions?

Thanks

Chadwick Posey


Unable to add the Hyperlink programmetically in ExcelCell using OfficeOpenXml

$
0
0

We are working on web-app where we need to modify the existing Excel file. We are using 'OfficeOpenXml' to modify the file.

Everything is working fine except Hyperlink, we are unable to add the hyper link programetically. Below is the code we used:

using OfficeOpenXml;

ExcelPackage xlPackage = new ExcelPackage(newFile);

worksheet = xlpackage.Workbook.Worksheets["WorkSheetName"];

worksheet.Cell(3, 4).Hyperlink = hyperlink; -(hyperlink System.Uri)

This code doesn't give any compile/runtime error but when we try to open the Excel file then the related Worksheet got corrupted.

Are there any ways to add Hyperlink programettically using C# to an Excel Cell in an existing Excel file?


Basavaraj

Reading SignatureLine from Excel

$
0
0

hi,

i want to read signature line present in Excel file... any help would be appreciated

i had tried workbook.Signature Property.

i need the signature line like following code do:

                   using (var document = WordprocessingDocument.Open(FILENAME, false))
                    {
                        _lstSigVar = document.MainDocumentPart.Document.Descendants<SignatureLine>().ToList();
                        if (_lstSigVar.Count > 0)//check if SigLine(s) present
                        {
                            for (int i = 0; i < _lstSigVar.Count; i++)
                                lstSigners.Items.Add(_lstSigVar[i].Id + " " + _lstSigVar[i].SuggestedSigner);
                        }
                    }

so by above code i got SignatureLine object which is easy to use for further processing



Haseeb Hasan Principle Software Engineer Ascertia Pvt Ltd

Viewing all 1288 articles
Browse latest View live


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