openxml-sdk

Export DataTable to Excel with Open Xml SDK in c#

你离开我真会死。 提交于 2019-11-26 18:37:21
Sorry for my english please. I'm new in open xml sdk. My program have ability to export some data and DataTable to Excel file (template) In the template I insert the data to some placeholders. It's works very good, but I need to insert a DataTable too... My sample code: using (Stream OutStream = new MemoryStream()) { // read teamplate using (var fileStream = File.OpenRead(templatePath)) fileStream.CopyTo(OutStream); // exporting Exporting(OutStream); // to start OutStream.Seek(0L, SeekOrigin.Begin); // out using (var resultFile = File.Create(resultPath)) OutStream.CopyTo(resultFile); Next

openxml spreadsheat save-as

痞子三分冷 提交于 2019-11-26 18:28:11
问题 I have an Excel 2007 spreadsheet that I edit with the OpenXML SDK 2. I remove some rows etc. I would like to know how to save that Spreadsheetdocument to another filename. 回答1: To my knowledge there is no built in way to change the filename, but since one way to edit the file is to use streams you can easily give the name of the file you want when writing out the contents of a stream: byte[] byteArray = File.ReadAllBytes("C:\\temp\\oldName.xltx"); using (MemoryStream stream = new MemoryStream

Using OpenXmlReader

孤者浪人 提交于 2019-11-26 16:27:34
问题 I hate to resort to StackOverflow for something so (seemingly) basic, but I've been fighting with Microsoft for the last few hours and seem to be hitting a dead end. I am trying to read (large) Excel 2007+ spreadsheets, and Google has kindly informed me that using the OpenXml SDK is a pretty popular choice. So I gave the thing a shot, read some tutorials, checked Microsoft's own library pages, and got very little out of them all. I am using a small test spreadsheet with just one column of

How can I embed any file type into Microsoft Word using OpenXml 2.0

爷,独闯天下 提交于 2019-11-26 16:19:10
问题 I spent a lot of time trying to figure out a good way to embed any file into Microsoft Word using OpenXml 2.0; Office documents are fairly easy but what about other file types such as PDF, TXT, GIF, JPG, HTML, etc.... What is a good way to get this to work for any file type, in C#? 回答1: Embedding Foreign Objects (PDF, TXT, GIF, etc…) into Microsoft Word using OpenXml 2.0 (Well, in collaboration with COM) I got a lot from this site, so here I asked and answered my own question in order to give

Why appending AutoFilter corrupts my excel file in this example?

杀马特。学长 韩版系。学妹 提交于 2019-11-26 14:47:30
问题 Hi I use the below method to apply an AutoFilter : public static void ApplyAutofilter(string fileName, string sheetName, string reference) { using (SpreadsheetDocument document = SpreadsheetDocument.Open(fileName, true)) { IEnumerable<Sheet> sheets = document.WorkbookPart.Workbook.GetFirstChild<Sheets>().Elements<Sheet>().Where(s => s.Name == sheetName); var arrSheets = sheets as Sheet[] ?? sheets.ToArray(); string relationshipId = arrSheets.First().Id.Value; var worksheetPart =

Replace bookmark text in Word file using Open XML SDK

耗尽温柔 提交于 2019-11-26 13:44:49
问题 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? 回答1: Here's my approach after using you guys as inspiration: IDictionary<String, BookmarkStart>

Applying % number format to a cell value using OpenXML

雨燕双飞 提交于 2019-11-26 12:28:03
问题 I want to apply the % (percentage) number format using open XML C# I have numeric value 3.6 that I want to display that number in excel as `3.6%. How do I achieve that? 回答1: WorkbookStylesPart sp = workbookPart.AddNewPart<WorkbookStylesPart>(); Create a stylesheet, sp.Stylesheet = new Stylesheet(); Create a numberingformat, sp.Stylesheet.NumberingFormats = new NumberingFormats(); // #.##% is also Excel style index 1 NumberingFormat nf2decimal = new NumberingFormat(); nf2decimal.NumberFormatId

OpenXML SDK: Make Excel recalculate formula

蹲街弑〆低调 提交于 2019-11-26 11:07:32
问题 I update some cells of an Excel spreadsheet through the Microsoft Office OpenXML SDK 2.0. Changing the values makes all cells containing formula that depend on the changed cells invalid. However, due to the cached values Excel does not recalculate the formular, even if the user clicks on \"Calculate now\". What is the best way to invalidate all dependent cells of the whole workbook through the SDK? So far, I\'ve found the following code snippet at http://cdonner.com/introduction-to-microsofts

From Excel to DataTable in C# with Open XML

和自甴很熟 提交于 2019-11-26 10:29:04
问题 I\'m using Visual Studio 2008 and I need create a DataTable from a Excel Sheet using the Open XML SDK 2.0. I need to create it with the DataTable columns with the first row of the sheet and complete it with the rest of values. Does anyone have a example code or a link that can help me to do this? 回答1: I think this should do what you're asking. The other function is there just to deal with if you have shared strings, which I assume you do in your column headers. Not sure this is perfect, but I

Optimal way to Read an Excel file (.xls/.xlsx)

倾然丶 夕夏残阳落幕 提交于 2019-11-26 09:17:30
问题 I know that there are different ways to read an Excel file: Iterop Oledb Open Xml SDK Compatibility is not a question because the program will be executed in a controlled environment. My Requirement : Read a file to a DataTable / CUstom Entitie s (I don\'t know how to make dynamic properties/fields to an object[column names will be variating in an Excel file]) Use DataTable/Custom Entities to perform some operations using its data. Update DataTable with the results of the operations Write it