openxml-sdk

Open XML SDK 2.0 to get access to excel 2010 worksheet by name

浪尽此生 提交于 2019-12-04 10:11:39
问题 I have an Excel 2010 spreadsheet that has 3 worksheets named Sheet1, Sheet2 and Sheet3. I'm trying to get a reference to a worksheet by name. I'm using the code: using (SpreadsheetDocument myWorkbook = SpreadsheetDocument.Open(FileName, true)) { //Access the main Workbook part, which contains all references WorkbookPart workbookPart = myWorkbook.WorkbookPart; WorksheetPart worksheetPart = workbookPart.WorksheetParts.Last(); // this gives me Sheet1 SheetData sheetData = worksheetPart.Worksheet

Corrupt document after calling AddAlternativeFormatImportPart using OpenXml

两盒软妹~` 提交于 2019-12-04 08:07:52
I am trying to create an AddAlternativeFormatImportPart in a .docx file in order to reference it in the document via an AltChunk. the problem is that the code below causes the docx file to read as corrupted by Word and cannot be opened. string html = "some html code." string altChunkId = "html234"; var document = WordprocessingDocument.Open(inMemoryPackage, true); var mainPart = document.MainDocumentPart.Document; var mainDocumentPart = document.MainDocumentPart; AlternativeFormatImportPart chunk = mainDocumentPart.AddAlternativeFormatImportPart (AlternativeFormatImportPartType.Xhtml,

Is there a tool to find errors in Excel documents created with the OpenXML SDK?

有些话、适合烂在心里 提交于 2019-12-04 07:41:44
Is there a tool that can identify the exact location of errors in an Excel document created using the OpenXML SDK? I've created an Excel file using the Microsoft OpenXML SDK 2.5 (also tried v 2.0 with the same result), and must have made a mistake somewhere in the code. What I'm trying to find out is where. The SDK validation functions all say the document is valid. When validating the generated Excel file using the OpenXML SDK Productivity tool, the response is "No validation error is found in the package". But.. when opening the Excel file using MS Excel, an error alerts the user that the

How to set Excel “Print Titles” with OpenXML

感情迁移 提交于 2019-12-04 06:41:52
问题 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? 回答1: The property is directly saved in the SpreadsheetPrintingParts object, however, this doesn't appear to be fully integrated into OpenXML as of yet, and requires passing a base64 string in to the variable. (see here) The content of this string appears to be tied to the machine the file is opened on, which didn't work for my implementation - I wasn't able to create a

How can I get the Worksheetpart from name or sheet ID in OpenXML?

倖福魔咒の 提交于 2019-12-04 06:31:14
The following creates an XLSX, adds two worksheets with some data. I then want to be able to get the spreadsheet later based on name (or preferably the id) so I can add/modify the sheets at a later point in time. I'm stuck on how to get the sheet again where the code is incomplete below. Sub Main() Using doc As SpreadsheetDocument = SpreadsheetDocument.Create(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "c:\temp\fubar.xlsx"), SpreadsheetDocumentType.Workbook) Dim currSheet As WorksheetPart ' create the workbook doc.AddWorkbookPart() doc.WorkbookPart.Workbook = New Workbook()

How do I unlock a content control using the OpenXML SDK in a Word 2010 document?

对着背影说爱祢 提交于 2019-12-04 05:36:53
I am manipulating a Word 2010 document on the server-side and some of the content controls in the document have the following Locking properties checked Content control cannot be deleted Contents cannot be edited Can anyone advise set these Locking options to false or remove then altogether using the OpenXML SDK? The openxml SDK provides the Lock class and the LockingValues enumeration for programmatically setting the options: Content control cannot be deleted and Contents cannot be edited So, to set those two options to "false" ( LockingValues.Unlocked ), search for all SdtElement elements in

C# to replace strings of text in a docx

喜你入骨 提交于 2019-12-04 05:35:25
Using C#, is there a good way to find and replace a text string in a docx file without having word installed on that machine? Yes, using Open XML . Here's an article which addresses your specific question: Creating a Simple Search and Replace Utility for Word 2007 Open XML Format Documents You may also try Aspose.Words for .NET in order to find and replace text in Word document . This component doesn't require MS Office to be installed. The API is quite simple and easy to use and implement. Disclosure: I work as developer evangelist at Aspose. 来源: https://stackoverflow.com/questions/3375811/c

Creating an ImagePart isn't saving the Relationship in OpenXML

前提是你 提交于 2019-12-04 04:24:31
问题 --Updated to provide full working class example, with 2 sample documents-- www.sklinar.co.uk/wp-content/uploads/mydoc.docx - Original Document with a INCLUDETEXT instruction to merge in Footer.Docx www.sklinar.co.uk/wp-content/uploads/footer.docx I have added a ImagePart to my document as well as using FeedData() to supply it with streamed content. But all I can get to appear in my document is a red box. My initial code Creates a Run with a Drawing as it's child: --For this example, I've used

Excel add data to WorksheetPart in code behind

狂风中的少年 提交于 2019-12-04 03:34:10
Hello guys I am creating an Excel file with 3 worksheets in the following code. using (SpreadsheetDocument spreadSheet = SpreadsheetDocument.Create(path + @"\UrlReport.xlsx", SpreadsheetDocumentType.Workbook)) { // create the workbook spreadSheet.AddWorkbookPart(); spreadSheet.WorkbookPart.Workbook = new DocumentFormat.OpenXml.Spreadsheet.Workbook(); // CREATE FIRST SHEET WorksheetPart newWorksheetPart1 = spreadSheet.WorkbookPart.AddNewPart<WorksheetPart>(); newWorksheetPart1.Worksheet = new DocumentFormat.OpenXml.Spreadsheet.Worksheet(); // create sheet data newWorksheetPart1.Worksheet

What's the difference between <c t=“str”> and <c><is> in Office Open XML?

喜你入骨 提交于 2019-12-04 03:11:29
问题 What's the difference between these two Office Open XML fragments? <c r="A2" t="str"> <v>btyler</v> </c> and <c r="B2"> <is><t>btyler</t></is> </c> note: The second sample I created manually based on the spec, the first is from an actual Excel workbook. Both seem valid and pretty much identical according to the spec, so I'm wondering why there is t="str" when <is> seemingly does the same thing. When does Excel choose to use one over the other? 回答1: According to the documentation at 18.18.11