openxml

Replace bookmark text in Word file using Open XML SDK

可紊 提交于 2019-11-27 07:39:01
I assume v2.0 is better... they have some nice "how to:..." examples but bookmarks don't seem to act as obviously as say a Table... a bookmark is defined by two XML elements BookmarkStart & BookmarkEnd . We have some templates with text in as bookmarks and we simply want to replace bookmarks with some other text... no weird formatting is going on but how do I select/replace bookmark text? Here's my approach after using you guys as inspiration: IDictionary<String, BookmarkStart> bookmarkMap = new Dictionary<String, BookmarkStart>(); foreach (BookmarkStart bookmarkStart in file.MainDocumentPart

reading Excel Open XML is ignoring blank cells

北慕城南 提交于 2019-11-27 07:33:15
I am using the accepted solution here to convert an excel sheet into a datatable. This works fine if I have "perfect" data but if I have a blank cell in the middle of my data it seems to put the wrong data in each column. I think this is because in the below code: row.Descendants<Cell>().Count() is number of populated cells (not all columns) AND: GetCellValue(spreadSheetDocument, row.Descendants<Cell>().ElementAt(i)); seems to find the next populated cell (not necessarily what is in that index) so if the first column is empty and i call ElementAt(0), it returns the value in the second column.

Inserting Image into DocX using OpenXML and setting the size

巧了我就是萌 提交于 2019-11-27 07:26:34
I am using OpenXML to insert an image into my document. The code provided by Microsoft works, but makes the image much smaller: public static void InsertAPicture(string document, string fileName) { using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(document, true)) { MainDocumentPart mainPart = wordprocessingDocument.MainDocumentPart; ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); using (FileStream stream = new FileStream(fileName, FileMode.Open)) { imagePart.FeedData(stream); } AddImageToBody(wordprocessingDocument, mainPart.GetIdOfPart

Save modified WordprocessingDocument to new file

左心房为你撑大大i 提交于 2019-11-27 07:24:53
I'm attempting to open a Word document, change some text and then save the changes to a new document. I can get the first bit done using the code below but I can't figure out how to save the changes to a NEW document (specifying the path and file name). using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using DocumentFormat.OpenXml.Packaging; using System.IO; namespace WordTest { class Program { static void Main(string[] args) { string template = @"c:\data\hello.docx"; string documentText; using (WordprocessingDocument wordDoc =

Cell styles in OpenXML spreadsheet (SpreadsheetML)

杀马特。学长 韩版系。学妹 提交于 2019-11-27 06:53:01
I've generated a .xlsx spreadsheet in C# using the OpenXML SDK, but can't figure out how to get cell styles working. I've been studying files produced by Excel, and can't quite figure out how it's done. Right now, I'm creating a fill, creating a CellStyleFormat that points at the fill, creating a CellFormat that points at the index of the CellStyleFormat , then creating a CellStyle that points to the CellFormat . Here's the code I'm using to generate the document: Console.WriteLine("Creating document"); using (var spreadsheet = SpreadsheetDocument.Create("output.xlsx", SpreadsheetDocumentType

Matching Excel's floating point in Java

痴心易碎 提交于 2019-11-27 06:40:45
问题 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 will display for this cell. In the underlying XML, we have: <v>-130.98999999999069</v> When trying to read the workbook with Apache POI, it feeds the number from the XML through Double.valueOf and comes up with: -130

OLE DB vs OPEN XML SDK vs Excel.interop

蓝咒 提交于 2019-11-27 05:45:32
问题 I need to read XLSX files and extract a maximum amount of content from it. Which of the API's should I use? OLE DB, open XML SDK, or Excel Interop? Which is the easiest to use? Can you retrieve all the information using one or the other? i.e, date, times, merged cells, tables, pivottables, etc. 回答1: You can try all of them and choose the one that fits you most... Depending on data you want to read, I'd suggest you to use Open XML over Interop or Ole DB. I don't know an open XML SDK, although

OPENXML with xmlns:dt

不羁的心 提交于 2019-11-27 05:32:02
Use OPENXML to get dt element in MSSQL 2005. How can I get xmlns:dt element in xml? For example, get a result set of two rows that list product id and country code. 121403 GBR 121403 USA declare @xmldata xml set @xmldata = '<?xml version="1.0"?> <data xmlns="http://www.aaa.com/master_browse_response" xmlns:dt="http://www.aaa.com/DataTypes"> <products> <product> <product_id><![CDATA[121403]]></product_id> <countries> <dt:country>GBR</dt:country> <dt:country>USA</dt:country> </countries> </product> </products> </data>' DECLARE @hDoc int, @rootxmlns varchar(100) SET @rootxmlns = '<root xmlns:hm=

how to create and download excel document using asp.net

故事扮演 提交于 2019-11-27 05:30:08
问题 How to create and download excel document using asp.net ? The purpose is to use xml, linq or whatever to send an excel document to a customer via a browser. Edit : Use case The customer load a gridview ( made with ajax framework ) in a browser, the gridview is directly linked to an sql database. I put a button 'export to excel' to let customer save this gridview data on his computer ansd i would like to launch a clean download of an excel. The solutions proposed here are not clean, like send

Inserting newlines in Word using OpenXML

寵の児 提交于 2019-11-27 04:20:23
I am using openxml WordProcessingDocument to open a Word template and replace placeholder x1 with a string. This works fine unless I need the string to contain a newline. How can I replace x1 with text may contain newlines that word would recognise? I have tried \n \r but these do not work Just to explain further when the word template is opened I read it into a StreamReader then use .Replace to replace x1. codeape To insert newlines, you have to add a Break instance to the Run . Example: run.AppendChild(new Text("Hello")); run.AppendChild(new Break()); run.AppendChild(new Text("world")); The