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

How to validate a Word document using OpenXML SDK 2.5?

$
0
0

I am trying to validate a 2013 Word document. The document is fully editable in Word 2013, "Check for Issues / Inspect Document" and "Check for Issues / Check Compatibility" do not report any problems.

However, while opening the document using OpenXML, I am getting error on the line with WordprocessingDocument.Open. The error is:
DocumentFormat.OpenXml.Packaging.OpenXmlPackageException: Invalid Hyperlink: Malformed URI is embedded as a hyperlink in the document.

Every sample about validation I have found goes like this:

using (WordprocessingDocument doc =
    WordprocessingDocument.Open(filepath, true))
    {                  
            OpenXmlValidator validator = new OpenXmlValidator();
...
What am I doing wrong? Is there another way to do it? 

Remove CellFormula using OpenXML

$
0
0

I want to remove cell formula using OpenXML. Please find below  my code.

If cell1.CellFormula IsNotNothingThen

cell1.CellFormula.Remove()

EndIf

I get a format corrupt error. Please help to resolve this issue.


WordML 2003 with Open Bookmark tags Migration

$
0
0

Hi

We have XML templates created in Word 2003 with open bookmarks which are not supported by MS anymore. We have about more than 14000 templates in our system. We need to migrate them to Word 2010 now.

As the open markups are not supported anymore, we are trying to replace them with Content controls. As the number of templates is very huge, it has to be automated by a custom tool. For this I need to find a way where I can read the old XML and replace the open bookmarks with content controls (sdt). Issue I've is that if you replace them the document doesn't open saying that the XML is invalid with some errors.

I cannot open the document and save as 2010 Word XML, as it results in loss of all the bookmarks.

Please suggest any approach that is feasible here.

-- VG

Differences in Excel spreadsheet when created from templates (XLTX)

$
0
0

Hi

In one of my projects I've discovered a strange difference which affects further working with the Excel spreadsheet.

First I create a new Excel spreadsheet from an existing template (XLTX) file using the following code:

    Public Function XLCreateExcelWbk(ByVal templatePath As String, ByVal workbookPath As String) As String

        Dim oldCulture As Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture
        System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
        File.Copy(templatePath, workbookPath, True)
        File.SetAttributes(workbookPath, FileAttributes.Normal)
        Using wbok As SpreadsheetDocument = SpreadsheetDocument.Open(workbookPath, True)
            wbok.ChangeDocumentType(SpreadsheetDocumentType.Workbook)
        End Using
        System.Threading.Thread.CurrentThread.CurrentCulture = oldCulture
        Return workbookPath

    End Function

When I compare the new file aith a manually created spreadsheet using Office 2010 the following difference is found in the file.

Difference

Is it something in my code or is this "by design"?

And, most importand, how can I adjust the spreadsheet so that it contains the same XML-code that tha manually created file?

Thanks in advance


Best Regards Peter Karlström Midrange AB, Sweden


Open Xml Sdk -Add Restricted Access

$
0
0

HI,

iam using open xml sdk 2.0 .i need to add restricted access to the users through Code .can any one help me to do code

Using C#, Openxml and Excel, how can I get the currently selected value from a Selection list?

$
0
0

I've been attempting to extract the value of a Selection list from within an excel spreadsheet. Retrieving the cell value of a cell with a dropdown simply returns '0'. Surrounding properties and/or validation objects don't seem to hold the answer either. This method works fine for other cells with different data types.

Any ideas anyone?

Thanks

Code I'm using here;

// Retrieve the value of a cell, given a file name, sheet name, 
    // and address name.
    public static string GetCellValue(string fileName,
        string sheetName,
        string addressName)
    {
        string value = null;

        // Open the spreadsheet document for read-only access.
        using (SpreadsheetDocument document =
            SpreadsheetDocument.Open(fileName, false))
        {
            document.WorkbookPart.Workbook.CalculationProperties.ForceFullCalculation = true;
            document.WorkbookPart.Workbook.CalculationProperties.FullCalculationOnLoad = true;

            // Retrieve a reference to the workbook part.
            WorkbookPart workbookPart = document.WorkbookPart;



            // Find the sheet with the supplied name, and then use that 
            // Sheet object to retrieve a reference to the first worksheet.
            Sheet theSheet = workbookPart.Workbook.Descendants<Sheet>().
              Where(s => s.Name == sheetName).FirstOrDefault();

            // Throw an exception if there is no sheet.
            if (theSheet == null)
            {
                throw new ArgumentException("sheetName");
            }

            // Retrieve a reference to the worksheet part.
            WorksheetPart wsPart =
                (WorksheetPart)(workbookPart.GetPartById(theSheet.Id));

            // Use its Worksheet property to get a reference to the cell 
            // whose address matches the address you supplied.
            Cell theCell = wsPart.Worksheet.Descendants<Cell>().
              Where(c => c.CellReference == addressName).FirstOrDefault();

            // If the cell does not exist, return an empty string.
            if (theCell != null)
            {
                value = theCell.InnerText;

                if (theCell.CellFormula !=null)
                {
                    value = theCell.CellValue.InnerText;
                }


                // If the cell represents an integer number, you are done. 
                // For dates, this code returns the serialized value that 
                // represents the date. The code handles strings and 
                // Booleans individually. For shared strings, the code 
                // looks up the corresponding value in the shared string 
                // table. For Booleans, the code converts the value into 
                // the words TRUE or FALSE.
                if (theCell.DataType != null)
                {
                    switch (theCell.DataType.Value)
                    {
                        case CellValues.SharedString:

                            // For shared strings, look up the value in the
                            // shared strings table.
                            var stringTable =
                                workbookPart.GetPartsOfType<SharedStringTablePart>()
                                .FirstOrDefault();

                            // If the shared string table is missing, something 
                            // is wrong. Return the index that is in
                            // the cell. Otherwise, look up the correct text in 
                            // the table.
                            if (stringTable != null)
                            {
                                value =
                                    stringTable.SharedStringTable
                                    .ElementAt(int.Parse(value)).InnerText;
                            }
                            break;

                        case CellValues.Boolean:
                            switch (value)
                            {
                                case "0":
                                    value = "FALSE";
                                    break;
                                default:
                                    value = "TRUE";
                                    break;
                            }
                            break;
                    }
                }
            }
        }
        return value;
    }

Create PPT slides of dynamic number via Open XML...

$
0
0

HI,

I need to create Slide Deck which will have dynamic number of slides. How it can be done ? Can i create slide parts in a loop as most of slides are same , it's just data will be different.

Let me know the way it is possible ?

Where are Microsoft headed with Office templates in Open XML SDK?

$
0
0

Hi

I have since a year back being forced to move my interop applications for Office document management in Windows server from Microsoft Office applications to Open XML SDK, as I'm sure is true for many other developers.

This has been a tough task, since no knowledge in Office object model has come to use in Open XML SDK.

One of the greatest disappointments is the lack of support for Office regular templates.

I have large companies as customers and one of the most important part in their management of documents, is the ability to control formats, building blocks and so on through templates.

Are Microsoft working with a fix to Open XML SDK to provide a way to create 100 % correct documents, spreadsheets and presentations from a template, or are the templates about to be obsolete?


Best Regards Peter Karlström Midrange AB, Sweden



Does the OpenXml API support adding 5 lines of footers left and right aligned to excel document?

$
0
0

Four lines of footers (line 1 through 4) left and right aligned work as expected.  WIth 5 lines we get an exception when opening the excel file.

Excel found unreadable content in "<filename>'.  Do you want to recover the contents of this workbook?

AFter clicing yes, we see a mesage about repairs (image attached).

Problems with merging two documents and adding header/footer

$
0
0

Hi

I have a WebService application creating Office documents using Open XML SDK for another web based document managment system.

The task for the webservice is to create new documents based on a template and some custom properties supplied in the call.
Now we have found some errors in some of the documents. We get errors when opened in MS Office 2007 and in 2010.
The error is a repair message, but even if word can repare the document (as far as we can see) we need to get this fixed.

If we open the document with Open XML SDK Productivity Tool, and validate the document with Validation option Office 2010,
we get errors in HeaderReference, AttachedTemplate, and AlternateContentChoice for First and Primary footer.

If we validate the document with Validation option Office 2007, you get the above errors and a whole lot of TableLook errors.

I have provided a package with error document,  sample code and testfiles on SkyDrive for anyone whos willing to help.
Link to shared folder: Link to sample package

Thanks in advance


Best Regards Peter Karlström Midrange AB, Sweden


Transer Open XML file into Dataset

$
0
0

I am trying to read the values of an excel file using the OPEN XML API, however I'm finding that the documentation is less than helpful.

I have a Strongly Typed DataTable and need to insert data into it from an excel file.  What is the best way to do this? 

In years past I would just load the Interop objects and loop through each cell value, but there doesn't appear to be a way to do that so far.

Thanks in advance.


jhoop

Able to open Word doc created but with errors

$
0
0

I am generating a Word doc using open XML. When I run the code on my own PC I don't get any errors, but when I deploy my code to a web server, users are getting two popup error messages. They are able to then view the document.

"Word found unreadable content in xxx.docx. Do you want to recover the contents of this document? If you trust the source of this document, click Yes." (click yes and another error appears)

"The file xxx.docx cannot be opened because there are problems with the contents." (clicking OK to this opens the document)

The code I am using is based on a sample I found on the open XML website for doing a mail merge. I have an existing .dotx template, I open it, replace the mail merge tags with my own content, and save.

I then stream that file to the browser like so:

 

Response.ClearContent();

Response.ClearHeaders();

Response.ContentType =

"application/vnd.openxmlformats-officedocument.wordprocessingml.document";

Response.AddHeader(

"Content-Disposition","attachment;filename=\"coverletter.docx\"");

Response.BinaryWrite(stream.GetBuffer());

Response.Flush();

openxml definedname - is name scoped to workbook or worksheet?

$
0
0
In a .Net app (not VSTO) I've used the DocumentFormat.OpenXml namespace to retrieve a list of DefinedNames from a file.  However, I noticed that one of the Excel files I tested this against had duplicated names referring to the same cell. 

 

I opened the file in Excel to investigate.  One name was scoped to the workbook, the other was scoped to a sheet.  I need to delete the name scoped to a sheet and keep the workbook level name, yet so far have been unable to figure out how to distinguish between the 2 names.  Looking over the DefinedName class on MSDN has given me no insight

 

Has anybody figured this out?

How to copy the spreadwheet with Macro using Open XML SDK

$
0
0
I have one spreadsheet with some macro embeded, and I want to use Open XML SDK to copy and paste in the same excel document, how to do it? I have one approach to copy the excel, but this approach cannot copy the macro itself.

Continuous section break in Word

$
0
0

I'm using OpenXML but can't insert a Continuous section break:

// Attempt 1 - add continuous section - NO effect in Word Doc

RunbreakRun =newRun();

SectionTypebreakSection =newSectionType();

breakSection.Val =

SectionMarkValues.Continuous;

breakRun.Append(breakSection);

paragraph1.Append(breakRun );

body.Append(paragraph1);

// Attempt 2 add continuous section as new paragraph - No effect in Word

body.Append(

newParagraph(newSectionType() { Val = SectionMarkValues.Continuous }));

// Attempt 3 - Add column break via "BreakValues", WORKS FINE, but BreakValues only contains  Column, Page og TextWrapping :-(

body.Append(

newParagraph(newRun(newBreak() { Type = BreakValues.Column })));

Many thanks,

Søren Godthardt Hansen



How to copy the spreadwheet with in same Workbook along with Macro using Open XML SDK

$
0
0

Hi,

Using OPM XML SDK 2.5 , i am trying to Create copy of a worksheet in same workbook. the source Worksheet is having a button control and a macro is assigned to this button.

When I create a copy of source work sheet, all the data and Button controls are copied into second worksheet in same work book. But macro assignment is not happening for the Button in second sheet. Could you please help me out on this how to assign macro code  to the button using OpenXML.

Thank you,

Kishan

Read Image and text from Excel using open xml

$
0
0
Dear All,
 
i have an excel file having Image and Text (Basically a Quiz paper). I have to read the .xlsx file and put the data into the database. I tried a lot but unable to do so. Plz help me to resolve the issue.
 
Thanks in Advance

how to set number data type format for a column in excel sheet

$
0
0

Hi,

We are exporting the data in Excel (xlsx) format file using OpenXML.

For all numeric values we have set the cell data type to number with respective style setting.

But the problem is we want the whole column to data type to be set as number. 

For .e.g. If data exported has 10 rows, then for column C1 all the cells in 10 rows will get the data type and format correctly to number as set. But we want to set number data type and format for C1 column, including all rows which are blank/empty in the sheet. 

From Excel application, this is easily possible by selecting the column and setting its format. However we are not able to figure out how to do this from code.

Any help will be appreciated.

Thanks,
Niren.

[Excel] Add Checkbox with OpenXML SDK and C#

$
0
0

Hi,

how can I add a checkbox to an Excel 2007/2010 document with the OpenXML SDK and C#?

Many thanks

Nico

Can we edit an opened active PowerPoint Presentation via Open XML SDK or Packaging

Viewing all 1288 articles
Browse latest View live


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