openxml

Creating Excel document with OpenXml sdk 2.0

◇◆丶佛笑我妖孽 提交于 2019-11-26 15:49:30
问题 I have created an Excel document using OpenXml SDK 2.0, now I have to style It, but I can`t. I don't know how to paint the background color or change the font size in different cells. My code to create a cell is: private static Cell CreateTextCell(string header, string text, UInt32Value index) { Cell c = new Cell(); c.DataType = CellValues.InlineString; c.CellReference = header + index; InlineString inlineString = new InlineString(); DocumentFormat.OpenXml.Spreadsheet.Text t = new

How to export a JQgrid data to Excel using c#?

烂漫一生 提交于 2019-11-26 15:27:27
I have made some research regarding this but most of the solutions are for MVC.. I am just using Asp.net 3.5 How could i achieve this on button click.. Should i include any library or anything else.. Please help.. Oleg The code which I posted in the answer can be used practically without any modification in any ASP.NET code which are written in C#. The helper class DataForExcel (see the file DataForExcel.cs ) has constructor public DataForExcel(string[] headers, List<string[]> data, string sheetName) or a little more "advanced" version public DataForExcel(string[] headers, DataType[]

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>

Inserting Image into DocX using OpenXML and setting the size

风格不统一 提交于 2019-11-26 13:08:40
问题 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

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

Cell styles in OpenXML spreadsheet (SpreadsheetML)

天涯浪子 提交于 2019-11-26 12:14:07
问题 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(\

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

open xml excel read cell value

怎甘沉沦 提交于 2019-11-26 06:39:15
问题 I am using the Open XML SDK to open an Excel xlsx file and I try to read the cellvalue on position A1 in each sheet. I use the following code: using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(openFileDialog1.FileName, false)) { var sheets = spreadsheetDocument.WorkbookPart.Workbook.Descendants<Sheet>(); foreach (Sheet sheet in sheets) { WorksheetPart worksheetPart = (WorksheetPart)spreadsheetDocument.WorkbookPart.GetPartById(sheet.Id); Worksheet worksheet =