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?

Categories

HOME
system-calls
sql-server-2014
ibm
spotfire
pandoc
flowtype
scapy
genexus
promotions
software-collections
cracking
osclass
guidewire
chef-recipe
lambda-calculus
react-select
web-testing
template10
web-parts
novacode-docx
project-structure
summernote
single-page-application
formulas
serenity-js
typedef
hololens
gnu-screen
datastax-enterprise
sha
android-cursorloader
proof-general
resx
kundera
2checkout
spring-oauth2
postgresql-9.6
availability
traitsui
mootools
incapsula
pyenv
android-databinding
const
julia-jump
ape-phylo
jks
activeandroid
hierarchical-clustering
automapper-4
text-formatting
pyopenssl
google-cloud-shell
overhead
disassembly
sharing
turbolinks
optional-parameters
queuing
django-taggit
transaction-isolation
containstable
gtkwave
identifying
euro
screen-lock
uiblureffect
tigase
disparity-mapping
visual-c#-express-2010
winrun4j
xtify
misfire-instruction
8-puzzle
nokogiri
bho
auctex
openafs
expresso-store
systrace
fileoutputstream
copyfile
clgeocoder
overlays
rollover
system-analysis
dynamic-scope
calendarextender
file-icons
vista64

Resources

Encrypt Message