c#
How to set the worksheet name with Excel Interop
using (XLWorkbook wb = new XLWorkbook()) { wb.Worksheets.Add(dt); wb.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; wb.Style.Font.Bold = true; Response.Clear(); Response.Buffer = true; Response.Charset = ""; Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment;filename= EmployeeReport.xlsx"); using (MemoryStream mymemorystream = new MemoryStream()) { wb.SaveAs(mymemorystream); mymemorystream.WriteTo(Response.OutputStream); Response.Flush(); Response.End(); } } The error message I'm getting is Worksheet names cannot be empty. How do I solve this?
The returned object of a worksheet adding operation is the worksheet itself. Change the worksheet name on that object: var ws = wb.Worksheets.Add(dt); ws.Name = "my sheet name"; Also, because you're using a DataTable as your source for the sheet, you have to make sure the table has a name: dt.TableName = "my sheet name"; MSDN reference: https://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.worksheet.name.aspx?f=255&MSPPError=-2147217396
Related Links
C# HtmlHelpers How to Escape / Preserve underscores in attribute names
Specific A* Pathfinding Issue with Implementation
Better way to retrieve image MVC?
How does the request is not lost when the first thread has returned? [closed]
Regex to verify phone numbers headers [duplicate]
(?,?…?) or (#field1,#field2…#fieldn) in parmeterized queries?
Find the upper left position of a canvas
Split a string based on spaces (unless in quotes) and remove the quotes afterwards [duplicate]
C# - Counting occurrences of numbers in order in an array
Automatically invoked custom serializer to subclasses in WCF
CS0656 Missing compiler required member : exception on run AddEventHandler (missing compiler required member)
Web API Simplest way to pickup a multipart/form-data response
How to assign value from url xml response to a variable in visual studio?
C# Server\Client using https and udp
C# - DataTable.Select() 'String was not recognized as a valid DateTime'
How to open PDF file in iOS?