closedxml

How to use a gradient fill (GradientFill) with ClosedXML

若如初见. 提交于 2019-12-05 06:38:33
I'm working on a C#/ASP.NET web thing and want to do an Excel export. First I found OpenXML, made some first steps, but it's really hard to use. Now, I'm using ClosedXML and it's quite a relief - so far. I came up with the problem to have a gradient fill on a table cell ... no problem with normal fills like worksheet.Cell(1,1).Style.Fill.SetBackgroundColor(XLColor.Red); or with Patterns like worksheet.Cell(1,1).Style.Fill.PatternType = XLFillPatternValues.LightHorizontal; worksheet.Cell(1,1).Style.Fill.PatternColor = XLColor.Green; worksheet.Cell(1,1).Style.Fill.PatternBackgroundColor =

How can I embed some VBA code into a spreadsheet created using ClosedXML?

懵懂的女人 提交于 2019-12-05 03:59:29
I am using ClosedXML to generate spreadsheets from C# (asp.net-mvc) and it works great. I have one additional requirement so I wanted to get some feedback on how I could achieve this. I want to save as a macro enabled workbook and when I just give it a "xlsm" extension it doesn't seem to open (versus a xlsx). Here is my code: public ActionResult ExportExcel() { MemoryStream stream = nModel.GenerateSS(); return File(stream, @"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml", "MySS.xlsx"); } but if I try to do this: public ActionResult ExportExcel() { MemoryStream

ClosedXML - Creating multiple pivot tables

﹥>﹥吖頭↗ 提交于 2019-12-03 23:30:23
I am trying to export some data to an excel sheet S1 whose data would be shown as Pivoted views in the next two sheets S2 and S3 . I am able to create a single pivot and it works perfect. But when I create two pivots, the consequent Excel file renders as corrupt. By corrupt I mean, On clicking yes, I get this - Here is the code I am using to create the pivots - using XL = ClosedXML.Excel; ... XL.XLWorkbook wb = new XL.XLWorkbook(); dsData = Session["ExportData"] as DataSet; var sheet1 = wb.Worksheets.Add("output table"); sheet1.Cell(1, 1).InsertTable(dsData.Tables[0], "output table", true); //

issue with returning HttpResponseMessage as excel file in WebAPI

匆匆过客 提交于 2019-12-02 05:16:31
I have created WebAPI which returns an excel file using closedxml nuget. Basically it converts my DataTable to excel. I'm referring couple of links below, How to return a file (FileContentResult) in ASP.NET WebAPI Returning binary file from controller in ASP.NET Web API Issue : excel generated on server path has NO issues. But when I download the same by returning it as HttpResponseMessage via webAPI the excel file is corrupted. It says, "The file is corrupt and cannot be opened" :( My Code : [System.Web.Http.AcceptVerbs("GET", "POST")] public HttpResponseMessage ExportExcel() { DataTable

How to append a new row to an Excel file using C# and ClosedXML?

淺唱寂寞╮ 提交于 2019-12-01 21:58:55
问题 I should append a new row to an existing Excel file. The task consists of two parts: Add to non-existing file (works well). Add to existing file (doesn't work: it doesn't make NEW record, displaying only the old record from "else" body). Here is my code: private static void ExportToEXCEL(DataTable dt, string paymentStoryPath) { if (File.Exists(paymentStoryPath)) { XLWorkbook currentWorkbook = new XLWorkbook(paymentStoryPath); IXLWorksheet currentWsh = currentWorkbook.Worksheet("Payment

Using closedXML C# library, How can I figure out what data is causing this error when trying to save

旧城冷巷雨未停 提交于 2019-12-01 16:20:43
问题 I have a C# app that exports to Excel using ClosedXML. It works fine but just ran into an issue where when i hit the : var ms = new MemoryStream(); workbook.SaveAs(ms); I get an exception: ' ', hexadecimal value 0x0B, is an invalid character Its definitely data related because it I look at certain data it works fine but other data it causes this issue. how can i figure out which character is causing the issue? Also, once I figure that out, what is the best way of finding where this character

export Gridview to Excel using ClosedXML without warning: the file you are trying to open is in a different format

余生颓废 提交于 2019-12-01 06:45:57
I am working on a ASP.NET 4.5 Webform and I have a Gridview (that has custom TemplateField and gets data from a sqlDataSource) I have this event to export the gridview contents to an excel sheet, and it does its jobs well except the created file is giving out an warning when user open it (which I understand because the file that got created is not an actual excel file): "the file you are trying to open is in a different format than specified by the file extension" protected void btnExport_Excel_Click(object sender, EventArgs e) { try { Response.Clear(); Response.Buffer = true; Response

Reach ActiveX or Form objects (textbox) from codebehind in an Excel document

本秂侑毒 提交于 2019-12-01 03:59:10
There are several textboxes in an excel file as ActiveX objects and I want to reach them from codebehind. I am using ClosedXML for other fields, but I am open for other suggestions. For accessing OLE objects from C#, add reference to Microsoft Forms 2.0 object library. You can iterate through the controls for your desired checkbox and textbox. Enjoy ! using Excel = Microsoft.Office.Interop.Excel; using VBE = Microsoft.Vbe.Interop.Forms; private static void ExcelOperation(string xlFileName) { var xlApp = new Excel.Application(); var xlWorkbook = xlApp.Workbooks.Open(xlFileName); var xlSheet =

How to set a data type for a column with ClosedXML?

落爺英雄遲暮 提交于 2019-12-01 02:29:47
问题 I see a lot of examples in documentation where data type for a cell is set: ws.Cell(1, 1).SetDataType(XLCellValues.Text); But when I try to set a data type for a column: ws.Column(1).SetDataType(XLCellValues.Text) ClosedXML generates a 5MB file and data type is not actually set. This operation works as expected in Excel (right-click on the column header, format cells, ...). If it is a limitation of ClosedXML, can it be easily fixed, or is there a workaround? 回答1: ClosedXML sets the data type

Reach ActiveX or Form objects (textbox) from codebehind in an Excel document

此生再无相见时 提交于 2019-11-30 23:53:11
问题 There are several textboxes in an excel file as ActiveX objects and I want to reach them from codebehind. I am using ClosedXML for other fields, but I am open for other suggestions. 回答1: For accessing OLE objects from C#, add reference to Microsoft Forms 2.0 object library. You can iterate through the controls for your desired checkbox and textbox. Enjoy ! using Excel = Microsoft.Office.Interop.Excel; using VBE = Microsoft.Vbe.Interop.Forms; private static void ExcelOperation(string