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

MsWord w:WriteProtection algorithm implementation

$
0
0

Hello.

MsWord(ooxml) have two pretty similar xml objects, w:DocumentProtection and w:WriteProtection.

First one, w:DocumentProtection can be password-encrypted using code from https://blogs.msdn.microsoft.com/vsod/2010/04/05/how-to-set-the-editing-restrictions-in-word-using-open-xml-sdk-2-0/

At first look, w:WriteProtection should use same code. But seems its wrong. Code that perfectly decrypt/encrypt w:DocumentProtection, cannot encrypt/decrypt password from w:WriteProtection.

So, how to encrypt/decrypt w:WriteProtection password in *right* way?

Thanks in advance.


Conversion of an Excel Flat OPC XML File to an Interop WorkSheet Object

$
0
0

Hi,

I've developed a COM Excel application with Office Interop, that runs when excel starts and that operates some calculation

In order to avoid to write an endless formatting code (with colors, styles, formula, ...) around data, I would like to create on-the-fly a new WorkSheet already formatted, starting from the XML of a formatted xlsx file (the xls file has been saved as XML and the XML has been included in the .Net solution) 

The idea is:

- read the XML 

- extract all the information of the worksheet (formula, styles,...)

- convert this into a WorkSheet interop object (to be added to the opened workbook, instead of to be saved somewhere)

Could someone give me some hints?

Many Thanks

Alberto

Created presentation using DocumentFormat.OpenXml always asking for repair in powerpoint.

$
0
0

Hello,

I currently have a problem Create a Presentation with DocumentFomat.OpenXml.

When I Opened the created presentation in powerpoint it always ask for "Repair".

Please help!

Best regards,
Kamaldeep

Redistribution of DLL files to target machines only DocumentFormat.OpenXml.dll required?

$
0
0

Hi there

Is DocumentFormat.OpenXml.dll the only required DLL to include with our application installer or are these also required?

System.IO.FileSystem.Primitives.dll
System.IO.Packaging.dll

I used NuGet to set it up on my local machine (v 2.9.1), 

Thank you.



Anthony

does this sdk support office 2016/office 365

$
0
0
i see there is a doc said that it supports office 2013:

https://docs.microsoft.com/en-us/office/open-xml/about-the-open-xml-sdk#open-xml-sdk-25-for-office

does this sdk support office 2016/office 365

dwdwd

Proofing errors not generating in the word documents (MS Word 2010)...

$
0
0

Hi,

This is Gururajan. I have developed one application for generating spell errors in word document (I am using MS Word 2010) using OpenXML C#. The tool which i developed is able to generate spell errors in some documents and not able to generate spell errors in some other documents even though the documents have spell errors. I did some R&D for those documents which the tool is not working. I converted the document (tool not working) to Xml for checking whether the "<w:proofErr w:type="spellStart" />" is found or not. I found the OpenXML element ("<w:proofErr w:type="spellStart" />") is not occurred in the Xml. This element ("<w:proofErr w:type="spellStart" />") is generating in some documents which are lower in size (some lower size documents also not generating the OpenXml element) and not generating in some documents which are more than 100 pages. Please provide a solution for this. I will look forward to hear from you.


Gururajan


Does it support in windows 10?

$
0
0

I am using this for creating spreadsheet in Windows 10 OS, MS office not installed.

Where MS office installed on Windows 10 not getting error.

I am getting error, Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

Thanks...


Open XML - Generated Excel Files are Corrupted

$
0
0

I am trying to export a large amount of data to Excel using Open XML SDK 2.5.  However I am not able to open larger files that are generated.  When I try to open the Excel files that are generated, I get a prompt that the file needs repairing.  

The code I am using is from the following link (The helper class I am using is unmodified from the article)- https://www.codeproject.com/Articles/877791/How-to-Create-Large-Excel-File-using-Openxml   

Here is the function I in my WPF code that I am calling the helper class from-

                                                 

        public static void LargeExportTest(List<ExcelData> arrExport, string filename, int sheetnumber, List<String> map)
        {
            try
            {
                int batchCount = 0;
                using (var spreadSheet = SpreadsheetDocument.Create(filename, SpreadsheetDocumentType.Workbook))
                {
                    // create the workbook
                    var workbookPart = spreadSheet.AddWorkbookPart();

                    var openXmlExportHelper = new OpenXmlWriterHelper();
                    //openXmlExportHelper.SaveCustomStylesheet(workbookPart);


                    var workbook = workbookPart.Workbook = new Workbook();
                    var sheets = workbook.AppendChild<Sheets>(new Sheets());

                    // create worksheet 1
                    var worksheetPart = workbookPart.AddNewPart<WorksheetPart>();
                    var sheet = new Sheet() { Id = workbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "Sheet1" };
                    sheets.Append(sheet);

                    using (var writer = OpenXmlWriter.Create(worksheetPart))
                    {

                        writer.WriteStartElement(new Worksheet());
                        writer.WriteStartElement(new SheetData());

                            for (int rowNum = 2; rowNum <= 4 - 1; rowNum++)
                        {

                            int u = Convert.ToInt32(rowNum.ToString());

                            writer.WriteStartElement(new Row() { RowIndex = Convert.ToUInt32(u) + 6 });

                            //insert test case name in first column
                            openXmlExportHelper.WriteCellValueSax(writer, arrExport[u].Name.ToString() == null ? "  x  "  : stripNonValidXMLCharacters(arrExport[u].Name.ToString()), CellValues.String);
                            int NextPosition = 0;
                            for (int col = 0; col < arrExport[u].ColumnData.Count; col++)
                            {
                                if (!((col + 1) >= arrExport[u].ColumnData.Count - 1))
                                {
                                    NextPosition = (arrExport[u].ColumnData[col + 1].ColumnNumber - arrExport[u].ColumnData[col].ColumnNumber);

                                }
                                else
                                {
                                    NextPosition = arrExport[u].ColumnData[col].ColumnNumber - 1;
                                }

                                for (int x = 0; x < NextPosition; x++)
                                {

                                    openXmlExportHelper.WriteCellValueSax(writer, "    Y    ", CellValues.String);


                                }


                                    openXmlExportHelper.WriteCellValueSax(writer, arrExport[u].ColumnData[col].ColumnData.ToString() == null ? String.Empty : stripNonValidXMLCharacters(arrExport[u].ColumnData[col].ColumnData.ToString()), CellValues.String);

                                    Console.WriteLine(arrExport[u].ColumnData[col].ColumnData.ToString());
                                Console.WriteLine(string.Format("Length: {0} , col is {1}, u is: {2}", arrExport[u].ColumnData[col].ColumnData.Length, col.ToString(), u.ToString()));
                            }
                            arrExport[u].ColumnData.Clear();  //reduce memory

                            writer.WriteEndElement(); //end of Row
                            batchCount++;
                        }

                        writer.WriteEndElement(); //end of SheetData
                        writer.WriteEndElement(); //end of worksheet
                        writer.Close();

                    }
                    //create the share string part using sax like approach too
                    openXmlExportHelper.CreateShareStringPart(workbookPart);

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

I am also including part of the sheet1.xml from one of the generated files-

<?xml version="1.0" encoding="utf-8"?><x:worksheet xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><x:sheetData><x:row r="8"><x:c t="str"><x:v>Rep1Req_Scr_5d694939-74a7-4f46-bc3f-36a3f9b15c42</x:v></x:c><x:c t="str"><x:v>    Y    </x:v></x:c><x:c t="str"><x:v>'1</x:v></x:c><x:c t="str"><x:v>    Y    </x:v></x:c><x:c t="str"><x:v>AAA</x:v></x:c><x:c t="str"><x:v>    Y    </x:v></x:c><x:c t="str"><x:v>XXX</x:v></x:c><x:c t="str"><x:v>    Y    </x:v></x:c><x:c t="str"><x:v>Rory Bradley</x:v></x:c><x:c t="str"><x:v>    Y    </x:v></x:c><x:c t="str"><x:v>'999999999</x:v></x:c><x:c t="str"><x:v>    Y   </x:v></x:c><x:c t="str"><x:v>SSN</x:v></x:c><x:c t="str"><x:v>    Y    </x:v></x:c><x:c t="str"><x:v>'999</x:v></x:c><x:c t="str"><x:v>    Y    </x:v></x:c><x:c t="str"><x:v>'000</x:v></x:c><x:c t="str"><x:v>    Y    </x:v></x:c><x:c t="str"><x:v>   Y    </x:v></x:c><x:c t="str"><x:v>    Y    </x:v></x:c><x:c t="str"><x:v>    Y    </x:v></x:c><x:c t="str"><x:v>   Y    </x:v></x:c><x:c t="str"><x:v>    Y    </x:v></x:c><x:c t="str"><x:v>    Y    </x:v></x:c><x:c t="str"><x:v>   Y    </x:v></x:c><x:c t="str"><x:v>    Y    </x:v></x:c><x:c t="str"><x:v>    Y    </x:v></x:c><x:c t="str"><x:v>   Y    </x:v></x:c></x:row></x:sheetData></x:worksheet>



XML REPORT

$
0
0

Hello everyone

I am working with a software that generate some report , but when i am trying to see those report are in blank in my computer in others computer they can see the report with all of the fields filled up , i would like to know if i need some dll, or program installed in my computer to see those report.

Thanks

Yoisbel.

System.IO.FileFormatException: 'File contains corrupted data.' after processing with ZipArchive

$
0
0

I have an XLSM file with invalid/broken URIs. So I ran the exact FixInvalidUri function provided in Eric's White blog "Handling Invalid Hyperlinks (OpenXmlPackageException) in the Open XML SDK" on this file.

Now I can open the resulting "fixed" XLSM file with Excel with no errors. I can also open it with 7Zip as an archive with no problems and view the individual XML files and confirm that the broken URIs have been fixed.

However, when I try to open the "fixed" file with Open XML (with var spreadsheetDocument = SpreadsheetDocument.Open("fixed.xlsm", false);) I get the exception "File contains corrupted data".

Why would this happen for what seems like a perfectly valid Excel file? Any idea what I can try to fix it? I don't see a way to attach my Excel file here as an example but if I can send it somewhere let me know....

How to loop through a word document and check whether the element is of type paragraph or SdtBlock in openXml

$
0
0

Hi ,

I want to loop through the word document and check what type of element it is and below is my code .

 foreach(var childElement in wordProcessingDocument.MainDocumentPart.Document.Body.Elements().ToList())
                {

                   if (childElement is DocumentFormat.OpenXml.Wordprocessing.SdtBlock )
                    {

                      //do something 

                     }

               }

But it never comes  to the loop even childElement  type is SdtBlock 

Any suggestion ?

Thanks 

How to find and delete text from word document

$
0
0

Hi,

Below is my code to search and delete text from word document , but it gives error and range can not be deleted 

Microsoft.Office.Interop.Word.Range rng1 = workDoc.Content;
                            object searchText = (object)outsideText;
                             object missing = System.Reflection.Missing.Value;
                             rng1.Find.Execute(ref searchText, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                                ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                                ref missing, ref missing);
                             object ps = rng1.Start;
                             object pe = rng1.End;
                             Microsoft.Office.Interop.Word.Range rng = workDoc.Range(ref ps, ref pe);
                             rng1.Delete(ref missing, ref missing);
                             workDoc.Save();

Any suggestion ?

Thanks in advance 

Read Page Numbers using OpenXML

$
0
0
How to read Page Numbers using OpenXML. Is there any alternate option or work around. Please suggest.

Open compared document using OpenXML

$
0
0
Using Word Interop, I am comparing two documents and opening the compared document at the end of the comparison. What is the option available using OpenXML.

Add watermark in Excel sheet

$
0
0

Hello All

I want to add a watermark(text) to a Excel document.

As a library for accessing the Excel document DocumentFormat.OpenXML is used.

Yours sincerely,

Vihaani.


Using OpenXml to copy large Excel file - Append data to same file

$
0
0

Hi .

I am trying to use Open XML to copy data from multiple datatables ( around 30+ datatables) . Each datatable contains 10000 rows and 255 columns .

I have tried multiple approach but, I am get the error of Memory Exception.

 private void ExportDataTable(DataTable table, string destination)
        {
            try
            {                

                using (var workbook = SpreadsheetDocument.Create(destination, DocumentFormat.OpenXml.SpreadsheetDocumentType.Workbook))
                {
                    var workbookPart = workbook.AddWorkbookPart();
                    workbook.WorkbookPart.Workbook = new DocumentFormat.OpenXml.Spreadsheet.Workbook();
                    workbook.WorkbookPart.Workbook.Sheets = new DocumentFormat.OpenXml.Spreadsheet.Sheets();

                    uint sheetId = 1;

                                 var sheetPart = workbook.WorkbookPart.AddNewPart<WorksheetPart>();
                        var sheetData = new DocumentFormat.OpenXml.Spreadsheet.SheetData();
                        sheetPart.Worksheet = new DocumentFormat.OpenXml.Spreadsheet.Worksheet(sheetData);

                        DocumentFormat.OpenXml.Spreadsheet.Sheets sheets = workbook.WorkbookPart.Workbook.GetFirstChild<DocumentFormat.OpenXml.Spreadsheet.Sheets>();
                        string relationshipId = workbook.WorkbookPart.GetIdOfPart(sheetPart);

                        if (sheets.Elements<DocumentFormat.OpenXml.Spreadsheet.Sheet>().Count() > 0)
                        {
                            sheetId =
                                sheets.Elements<DocumentFormat.OpenXml.Spreadsheet.Sheet>().Select(s => s.SheetId.Value).Max() + 1;
                        }

                        DocumentFormat.OpenXml.Spreadsheet.Sheet sheet = new DocumentFormat.OpenXml.Spreadsheet.Sheet() { Id = relationshipId, SheetId = sheetId, Name = table.TableName };
                        sheets.Append(sheet);

                        DocumentFormat.OpenXml.Spreadsheet.Row headerRow = new DocumentFormat.OpenXml.Spreadsheet.Row();

                        List<String> columns = new List<string>();
                        foreach (DataColumn column in table.Columns)
                        {
                            columns.Add(column.ColumnName);

                            DocumentFormat.OpenXml.Spreadsheet.Cell cell = new DocumentFormat.OpenXml.Spreadsheet.Cell();
                            cell.DataType = DocumentFormat.OpenXml.Spreadsheet.CellValues.String;
                            cell.CellValue = new DocumentFormat.OpenXml.Spreadsheet.CellValue(column.ColumnName);
                            headerRow.AppendChild(cell);
                        }

                        sheetData.AppendChild(headerRow);

                        foreach (DataRow dsrow in table.Rows)
                        {
                            DocumentFormat.OpenXml.Spreadsheet.Row newRow = new DocumentFormat.OpenXml.Spreadsheet.Row();
                            foreach (String col in columns)
                            {
                                DocumentFormat.OpenXml.Spreadsheet.Cell cell = new DocumentFormat.OpenXml.Spreadsheet.Cell();
                                cell.DataType = DocumentFormat.OpenXml.Spreadsheet.CellValues.String;
                                cell.CellValue = new DocumentFormat.OpenXml.Spreadsheet.CellValue(dsrow[col].ToString()); //
                                newRow.AppendChild(cell);
                            }

                            sheetData.AppendChild(newRow);
                        }
                                      
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

I have tried using a dataset and iterating for each datatable, this code breaks with Out of Memory exception , when the second datatable hits.

This method is called every time I am filling a datatable. I want to understand if this approach is correct, and how to save the file ? I would like to have only one excel file with multiple sheets. How to fix this?

Thanks

Wrap Text - Auto format rows

$
0
0

Hello,

I am using OpenXML to create reports, I am filling data in existing excel template file.

In excel template 'Wrap text' for all cells is set to true. When my report is complete I open excel file.

In opened file cells are not sized correctly with text wrapping (text wrapping is not applied). Also I observed on machine with office 2007 it works cell are wrapped but on office 2013 cell are not correctly wrapped. If I just double click on any cell then entire row is correctly updated.

Can someone please help me in this, is any property \tag I can set in openXML so that on document open cells are correctly shown.

Previously we were using OLE office interface there it works always so expectation is it should work with openXML too.

Thanks,

Dhanaj 

Read text, X, Y coordinates of shape placed on slide layout

$
0
0

Sorry for my English :)

I try read XY coordinates and text of shapes placed on the firstslide:

public static void Read(string presentationPath)
{
    using (var doc = PresentationDocument.Open(presentationPath, false))
    {
        var firstSlideShapes = doc.PresentationPart.SlideParts.First().Slide.CommonSlideData
            .ShapeTree.Elements<DocumentFormat.OpenXml.Presentation.Shape>();
        foreach (var shape in firstSlideShapes)
        {
            // If shape has text write to debug
            var texts = shape.Descendants<DocumentFormat.OpenXml.Drawing.Text>();
            foreach (var text in texts)
            {
                Debug.WriteLine(text.Text);
            }

            // Read x and y coordinates
            var t2D = shape.ShapeProperties.Transform2D;
            if (t2D != null)
            {
                Debug.WriteLine($"{t2D.Offset.X}:{t2D.Offset.Y}");
            }

            Debug.WriteLine("");
        }
    }
}

but I can not get Transform2D (is null) for the shape which placed onslide layout. Problem: some shape stores its text in the slide, but x, y in slide layout.

How can I get a text, x, and y of shape which stores its x,y in slide layout?


Compare formatting using OpenXML

$
0
0
How to compare formatting (Bold/Italic/etc.) of two word documents using OpenXML

PowerPoint found a problem with content in - Charts and Tables not showing after repair

$
0
0

I wrote some code based on the Open XML SDK about 10 years ago to create PowerPoint presentations and we are working to add some functionality. I have recompiled the code with the 2.8 SDK.  I start with a themed file and copy in layouts and slide objects. Everything works with two new files we created and older files that don't contain charts.  Any file we process that have charts have the error in the title of this post.  When I let PowerPoint repair the file all charts and tables are missing.

The files that are problems were originally created with PowerPoint 2007, but they still work in current production with Open XML SDK 2.0.

I have tried to identify the issue through the productivity tool using the validate feature, but have not found anything that pointed me to a specific issue.  Any advice on how to narrow down this problem would be greatly appreciated.

Note: I have gone through most of the posts with the same error message and none of the solutions for those have helped.


http://geekswithblogs.net/tmurphy

Viewing all 1288 articles
Browse latest View live


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