FAQ Database Discussion Community


Check docx is corrupted or not

c#,file,openxml
I tried many solution but code is always checking corrupted file and send true using (FileStream fileStream = File.OpenRead(path[0])) { MemoryStream memStream = new MemoryStream(); memStream.SetLength(fileStream.Length); fileStream.Read(memStream.GetBuffer(), 0, (int)fileStream.Length); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;...

Excel open xml sdk - Controling chart position

excel,openxml
I'm trying to figure out how to get the position of an existing chart on the sheet and understand what range (columns and rows) it "hides"... I have the chart part and chart element....

Unable to add two paragraphs in open xml word document

asp.net,vb.net,openxml
I am new to Open XML. This is what I have been able to achieve so far: Create a Word Document Add a Paragraph with some text Align text by changing justification property of paragraph Change font size & bold (on/off) I am trying to add two paragraphs with different...

How to 'Tag' regions of a Word Documents to make it easy to add text to them with Open Office XML?

c#,ms-word,openxml
My application needs to create a richly formatted Word document for the user. The process starts with two documents: A Word document template. A Word document that serves as a ‘database’ of paragraphs that can be added to the template document based on user input. Based on user input, the...

Change Sheet tab color of excel file using Open XML

openxml
I want to change the sheet tab color of an excel Xlsx document. I am using the following code but it does not set the sheet color. I get object reference exception when I set the sheet tab color. public static string filepath = @"C:\Test\Book1.xlsx"; private static void ChangeSheetcolor() {...

Trying to read an Excel file file stream in C#, I get numbers instead of text

c#,excel,openxml,memorystream
I'm trying to use DocumentFormat.OpenXml to read an uploaded Excel file. When I get the file (HttpPosteFileWrapper) I'm simply trying to read the cells and write them to a text string. (Later I will do more, but I'm just trying to get used to OpenXml right now.) My data in...

Read Excel file using OpenXML

c#,excel,openxml
I am writing a c# program to read excel file using OpenXML. I have a list of words added in a column in the excel file in a column.I want to read them and add to an array list. I am using the below code using (SpreadsheetDocument doc = SpreadsheetDocument.Open(filePatah...

Reading Powerpoint SmartArt in Java

apache-poi,powerpoint,openxml
I found Apache POI doesn't support reading SmartArt component. (Am I right?) So I tried Aspose.Slides and it worked. But the trial version has critical restriction. (can't get text has length over 5 characters) Can anybody help?...

Apply a TableStyle to a Word Table

c#,ms-word,openxml,docx
Trying to style a table using a predefined style but nothing is working. I've tried with a a newly created document and one created from a saved template. Using the SDK Productivity tool I can see the style is there in the template but it's not being applied. I've tried...

How to set Excel “Print Titles” with OpenXML

c#,excel,openxml,openxml-sdk
How can I set the "Print Titles" property of a spreadsheet with OpenXML, to have a row show at the top of every printed page? ...

How do you add text wrapping to a cell using OpenXml when creating excel files?

c#,asp.net,excel,openxml
How do you set the format of a text cell to wrap when generating .xlsx files with OpenXml? Here is the code I have currently: public void Excel() { var viewModel = new RequirementIndexData(); viewModel.Requirements = db.Requirement; MemoryStream ms = new MemoryStream(); SpreadsheetDocument dc = SpreadsheetDocument.Create(ms, SpreadsheetDocumentType.Workbook); WorkbookPart mdp =...

How to insert line break into Word (docx) document using OpenXMLPowerTools?

c#,.net,openxml,docx,openxml-sdk
I'm writing a library which generates Word documents based on a template. Some text needs to be replaced with another text. Everything seems to be working, there is a TextReplacer class which may perform replacements. The things become worse when I need to replace a single-line part of text with...

Get the Column Index of a Cell in Excel using OpenXML C#

c#,excel,openxml
I've been looking around for a while now and cannot seem to find out how to do this. I've got an excel sheet, which I'm reading using OpenXML. Now the normal thing would be to loop through the rows and then loop through the cells to get the values, which...

How to count rows per worksheet in OpenXML

c#,openxml
I switched from Interop library to OpenXML, because I need to read large Excel files. Before that I could use: worksheet.UsedRange.Rows.Count to get the number of rows with data on the worksheet. I used this information to make a progressbar. In OpenXML I do not know how to get the...

How to set xml DOCTYPE with Delphi / ADOM (OpenXML)?

xml,delphi,openxml,doctype
Using Adom 4.3, creating a new document with DI := TDomImplementation.Create; Doc := TDomDocumentNS.Create( DI ) How do I set the <!DOCTYPE ... line in the resulting XML doc? /not with inserting this line in a stringlist at the saving of the file/ The Doctypedecl property of the document is...

OpenXML does not help to read large Excel files contrary to documentation

c#,excel,openxml
The documentation says that: The following code segment is used to read a very large Excel file using the DOM approach. and then goes an example. I use it to implement reading a relatively large file with 700K rows. I have this code by now: using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(path,...

How to get rowspan and cospan of word document table using openXML

c#,vsto,openxml,openxml-sdk
i m very new to openXML, i m trying to get the colspan and rowspan value of the table in wordprocessingML. can any one explain how can i get these two values using openXML Thanks in advance...

How to read an option from XML in T-SQL?

sql-server,tsql,parsing,openxml
I have the next XML file: <?xml version="1.0" encoding="utf-8"?> <DynamicEntity Name="ProductsMilk"> <Field Name="Name" Type="nvarchar(256)" AllowNulls="false" /> <Field Name="Description" Type="ntext" AllowNulls="false" /> <Field Name="Price" Type="float" AllowNulls="false" /> </DynamicEntity> I need to read some value from any option of XML-node, for e.g. I need to read the value of Type option from...

How to add values to a PPTX using open XML SDK C#?

c#,sql,.net,powerpoint,openxml
Here is my requirement: I have a PPTX template with me. I used OPEN XML SDK's reflect code option to obtain the c# code. Now my requirement is to add values to the template from a SQL Server Database. It would be great if you can help me out with...

OpenXML xml snippet for a bulleted list

openxml,phpword
I am using PHPWord to ger nerate word elements. I want to insert a bulleted list using setValue in my template. I tried inserting this snippet <w:p> <w:pPr> <w:pStyle w:val="ListParagraph"/> <w:numPr> <w:ilvl w:val="0"/> <w:numId w:val="1"/> </w:numPr> </w:pPr> <w:r> <w:t>One</w:t> </w:r> </w:p> But somehow I am missing the style. where do...

Why does OpenXML read rows twice

c#,excel,openxml
I count rows in two worksheets like this: foreach (WorksheetPart worksheetPart in workbookPart.WorksheetParts) { OpenXmlPartReader reader = new OpenXmlPartReader(worksheetPart); if (count == 0) { while (reader.Read()) { if (reader.ElementType == typeof(Row)) { count_first++; } } } else if (count == 1) { while (reader.Read()) { if (reader.ElementType == typeof(Row)) {...

PHPWord corrupted file?

php,ms-word,openxml,docx,phpword
My basic PHPWord setup is working. This is my code: <?php require_once 'PhpWord/Autoloader.php'; \PhpOffice\PhpWord\Autoloader::register(); function getEndingNotes($writers) { $result = ''; // Do not show execution time for index if (!IS_INDEX) { $result .= date('H:i:s') . " Done writing file(s)" . EOL; $result .= date('H:i:s') . " Peak memory usage: "...

PHP replace text in Office OpenXML files with XMLWriter/XMLReader

php,xml,openxml,xmlreader
I'm using XMLReader to find text in a Office OpenXML document and XMLWriter to write it to a xliff file. I then modify the text in the other xml file and now I want to rebuild the OpenXML document. I am using the XML iterator class like suggesetd in this...

Specific order of xmlelements in Excel OpenXml Workbook class

c#,excel,openxml
I create PowerPoint presentations via OpenXml. The slides of the presentations are enriched with embedded objects. Typically Excel documents are embedded. Beside having the image and the document prepared for embedding, Excel needs another information which area shall be shown to the user when the document is opened in PowerPoint....

OpenXml.WordProcessing.Justification always comes as OpenXmlUnknownElement

.net,ms-office,openxml,openxml-sdk
I'm building a table using OpenXml and setting the Justification property for every cell. It doesn't really matter where I assign this property, either in the Run element or as a TableCellProperty, when the document is open using the Productivity Tool for MS Office the Justification element always comes as...

Numerical values in Excel 2007 - representation vs storage in the underlying xml file

c#,.net,excel,openxml
This question is related to .NET and OpenXml. I've already gone through the following article, it has good explanation, but not an answer to my question: Inconsistent visualization of numerical values in Excel 2007 vs the underlying xml file In my application, user is uploading an Excel (.xls/.xlsx) and I'm...

Convert HTML code to doc using PHP and PHPWord

php,html,openxml,phpword
I am using PHPWord to load a docx template and replace tags like {test}. This is working perfectly fine. But I want to replace a value with html code. Directly replacing it into the template is not possible. There is now way to do this using PHPWord, as far as...

Setting DefinedNames in OpenXML to set Print Titles for all worksheets in Excel

c#,excel,openxml,openxml-sdk
My end aim is to programatically set Excel's "Print Titles" value of Page Setup for all worksheets in my document. Initially I tried looking at using the SpreadsheetPrintingParts object (based on this question) - however, that requires generating a base 64 string, which seemingly has to come from an exisiting...

Excel Open xml sdk - Copy formula between cells with range modification

c#,excel,openxml,openxml-sdk
I have a cell with formula (CellFormula). I don't know the formula content (Might be Sum, ifs or any other calculation). The formula might include range. When you drag the cell to other cells (manually at excel application itself) the formula range get updated. I want the formula programatic copy...

Using WordprocessingDocument error: Unable to create mutex

c#,.net,openxml,docx,openxml-sdk
I'm using this simple pattern to create a docx file in an ASP.NET app: var outputFileName = "creating some file name here..."; var outputFile = string.Format("~/App_Data/files/{0}.docx", outputFileName); // creating a file stream to write to var outputStream = new FileStream(HttpContext.Current.Server.MapPath(outputFile), FileMode.OpenOrCreate); // creating the default template using (var sr =...

How to replace DataXML from Slide Diagram in Powerpoint using Apache POI

java,xml,apache,powerpoint,openxml
i want to replace the one data.xml file of power point presentation in java using apache API with other file data.xml For the reference i want to replace the following file with another power point file. Following is the code i have tried but xml isnt replacing. I have different...

How to create Excel file using OpenXML without creating a local file?

c#,excel,openxml,openxml-sdk
Is it possible to create and edit an excel document using OpenXML SDK without creating a local file? As per the documentation the "Create" method demands for a filepath, which creates a local copy of the file. SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(filepath, SpreadsheetDocumentType.Workbook); I'm referring the MSDN article here: https://msdn.microsoft.com/en-us/library/office/ff478153.aspx My...

OpenXML Merging Documents - How to See Content using Productivity Tool

openxml
I'm fairly new too and struggling with OpenXML. We basically have a Word template and depending on the number of records the user selects in a website we have, we pull the records out of the database and use the template to create a word document. Then we assemble all...

Problems retrieving content controls with Open XML sdk

ms-office,sharepoint-2013,openxml,openxml-sdk
I am developing a solution that will generate word-documents. The word-documents are generated on the basis of a template document which has defined content controls. Everything was working good for me when I had only one content control in my template, but after expanding the template document with more content...

How to use xmlDocument to check if certain attributes of the document exist

c#,xml,openxml,openxml-sdk,wordprocessingml
So I am trying to check whether a document has certain attributes. For example, I have a sample master thesis and one of the things I have to check is whether or not the title is centered on the title page. So far, I have created an xmlDocument object of...

Change default document layout when generating word document from OpenXML in C#

c#,ms-word,openxml
I've been able to generate a simple word document using a format similar to the format used in this SO question, however whenever I open the document it opens in print layout view. Is there a way that I can programmatically make it open in web layout view by default?

“External table is not in the expected format”

c#,excel,dataset,openxml,oledbdataadapter
I try to fill DataSet with Excel data (via OpenXML library to get sheet name), but some times i get error: "External table is not in the expected format". So, i use the same file= *.xlsx (i converted it from *.xls to *.xlsx via Excel 2010). Yesterday it works fine,...

How to Generate DataXML in OpenXML for powerpoint in java

java,xml,apache-poi,powerpoint,openxml
I have added one smart art shape in the Microsoft power point presentation slide. I have retrieved the data of that diagram in Java using apache POI. I want to generate my Own DataXML for that presentation from scratch using apache poi or any other free java API. How i...

How to get DataXML from Slide Diagram in Powerpoint using Apache POI

java,xml,apache-poi,powerpoint,openxml
I have added one smart art shape in the Microsoft power point presentation slide. I want to get the data of that diagram in Java using apache POI. How to retrieve the complete data.xml from first slide of presentation. I opened the presentation and following is the hierarchy of presentation....

Matching Excel's floating point in Java

java,excel,floating-point,apache-poi,openxml
I have an .xlsx spreadsheet with a single number in the top-left cell of sheet 1. The Excel UI displays: -130.98999999999 This is visible in the formula bar, i.e. not affected by the number of decimal places the containing cell is set to show. It's the most accurate number Excel...

OpenXML tag search

c#,.net,ms-word,openxml
I'm writing a .NET application that should read a .docx file nearby 200 pages long (trough DocumentFormat.OpenXML 2.5) to find all the occurences of certain tags that the document should contain. To be clear I'm not looking for OpenXML tags but rather tags that should be set into the document...

Ignore spelling error in DocX file

ms-word,openxml
Using OpenXML, I'm inserting some text into a document that I know will be marked as incorrectly spelt (because it's a product name) and will be marked with the angry red line when the file is opened in Word. How can I mark the XML so that it knows that...

Embedding Pdf with OpenXml in PowerPoint fails for newer versions

c#,pdf,powerpoint,openxml,ole
I need to progammatically embed Pdf documents in PowerPoint via OpenXml. According to this: Embedding files into Open XML documents using C# it is possible via OLE32.StgCreateStorageEx methods to create the necessary picture as well as the oleobject. Unfortunately this doesn't work with current versions of PDF. On a 64...

Unknown XSLT parse error

xml,node.js,xslt,openxml
I created an XSL transform that to transform MS Word documents (OpenXML) into HTML. The transform works fine if I link it to the XML file with: <?xml-stylesheet type="text/xsl" href="word-transform.xsl"?> And then open the XML file in a browser—like FireFox. But if I try to parse the transform with something...