openxml

OpenXML how to get cell in range

坚强是说给别人听的谎言 提交于 2019-12-23 16:12:58
问题 Please help me to get cell in range (ex from A:1 to E:11 are all cells in rectangular). For now, my ideal is Worksheet worksheet = GetWorksheet(document, sheetName); SheetData sheetData = worksheet.GetFirstChild<SheetData>(); IEnumerable<Cell> cells = sheetData.Descendants<Cell>().Where(c => c.CellReference >= A:1 && c.CellReference <= E:11 && ); int t = cells.Count(); But this code does not work. Thanks 回答1: It won't be that easy to compare cell's CellReference with a string. And yes, what

How to set a List for data validations in column/columns of excel file using OpenXml in c#?

时光怂恿深爱的人放手 提交于 2019-12-23 15:03:33
问题 I need to create a dropdown using a particular list as source in column/columns of an excel file using openXml. I use the following code for the purpose, SpreadsheetDocument spreadSheetDocument = SpreadsheetDocument.Open("C:\\Users\\Harun.TV\\Desktop\\OpenXml\\1.xlsx",true); WorkbookPart workbookpart = spreadSheetDocument.WorkbookPart; Workbook workbook=workbookpart.Workbook; WorksheetPart worksheetPart=workbookpart.WorksheetParts.First(); DataValidations dataValidations1 = new

'The file is corrupt and cannot be opened' OpenXML

余生颓废 提交于 2019-12-23 13:58:17
问题 I got that code from OpenXML sdk and instead of SpreadsheetDocument.Create , I used SpreadsheetDocument.Open This code is working and add an image in .xlsx , after image added to the file. I open the file which shows -> The file is corrupt and cannot be opened If you want more details Please! let me know. Reference URL -> https://code.msdn.microsoft.com/office/How-to-insert-image-into-93964561 Thanks for the help! /// <summary> /// add sheet in xlsx then add image into it. /// </summary> ///

OpenXML get sheet name from Worksheet

偶尔善良 提交于 2019-12-23 13:19:07
问题 I'm iterating over my worksheets like so WorkbookPart wbPart = doc.WorkbookPart; SharedStringTablePart sstPart = wbPart.GetPartsOfType<SharedStringTablePart>().First(); SharedStringTable sst = sstPart.SharedStringTable; foreach (var wsp in wbPart.WorksheetParts) { Worksheet ws = wsp.Worksheet; // i want to do something like this if (ws.Name == "People_Sheet") { } } I need to know which sheet i'm processing so I can handle it differently. How can I get the name of the sheet (that is displayed

OpenXML get sheet name from Worksheet

自闭症网瘾萝莉.ら 提交于 2019-12-23 13:18:08
问题 I'm iterating over my worksheets like so WorkbookPart wbPart = doc.WorkbookPart; SharedStringTablePart sstPart = wbPart.GetPartsOfType<SharedStringTablePart>().First(); SharedStringTable sst = sstPart.SharedStringTable; foreach (var wsp in wbPart.WorksheetParts) { Worksheet ws = wsp.Worksheet; // i want to do something like this if (ws.Name == "People_Sheet") { } } I need to know which sheet i'm processing so I can handle it differently. How can I get the name of the sheet (that is displayed

Specified part does not exist in the package

▼魔方 西西 提交于 2019-12-23 12:44:18
问题 I have the following code: using (var doc = WordprocessingDocument.Open(filename, true)) { .... } Where string filename is a valid path to a docx file. But calling Open causes the following InvalidOperationException: Specified part does not exist in the package. Edit: I assume the problem is due to the docx file I'm trying to open being invalid so I'll post the xml: <?xml version="1.0" encoding="utf-8" standalone="yes"?> <w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010

Adding a date in an Excel cell using OpenXML

隐身守侯 提交于 2019-12-23 11:57:18
问题 This is what I am doing: CellFormat cellFormat = new CellFormat() { NumberFormatId = (UInt32Value)14U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyNumberFormat = true }; sd.WorkbookPart.WorkbookStylesPart.Stylesheet.CellFormats.AppendChild<CellFormat>(cellFormat); _dateStyleIndex = sd.WorkbookPart.WorkbookStylesPart.Stylesheet.CellFormats.Count() - 1; and then somewhere later in my code else if (type == DataTypes.DateTime) {

Convert HTML code to doc using PHP and PHPWord

折月煮酒 提交于 2019-12-23 09:56:10
问题 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 I know. I looked at htmltodocx. But it seams it will not work either, is it posible to transform a peace of code like <p>Test<b>test</b><br>test</p> to a working doc markup? I only need the basic code, no styleing. but Linebreaks have

Set text align to center in an Excel document using OpenXML with C#

二次信任 提交于 2019-12-23 09:30:38
问题 I have a document that my asp.net page is creating and I need to align the text of certain columns to center. I have opened the document after manually center the columns in openXML SDK but the code that is reflected does not achieve the desired outcome. This is how I am setting the custom widths of these columns and I would like to add to this function (method, whatevs) the capability to center the text: private static Column CreateColumnData(UInt32 StartColumnIndex, UInt32 EndColumnIndex,

Fastest way to read from and write to Excel using C# [duplicate]

余生颓废 提交于 2019-12-23 04:24:22
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: What is the best / fastest way to export large set of data from C# to excel I am creating a web application with the following functionality: Assume an admin stores some data in a predefined Excel template file. He will visit the Admin page and upload this Excel. The application reads this Excel and updates data in the database accordingly. The data stored in the database has to be displayed to any user visiting