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

Client found response content type of 'multipart/related
displaying a div tag from code behind
Placing dlls in bin directory after successfull build
Call function in dynamic linq
iTextSharp PdfPtable multipage
Replace same multiple chars with one char [closed]
Send email using smtp client in c#
WPF If helper classes are bad, how do you properly eliminate duplicate code?
How to use 'In' SQL keyword in Entity Framework?
C# Printing variables using an “EXEC” Command [closed]
WP8 City lens immitation
Xamarin android class name references
Visual Studio 2003 C#, struct compiling erro
Multiple Tests running in windows forms simultaneously
Mapping the other table in a many to many relationship
save form on code behind

Categories

HOME
max
azure-documentdb
gaussian
mediarecorder
virtualhost
annyang
rtc
adroitlogic
guidewire
cakephp-2.0
webseal
ofbiz
android-actionbar
civicrm
xna
connectiq
opengraph
fastboot
matlab-gui
aws-iot
quality-center
aspxgridview
nsopenpanel
akavache
android-6.0-marshmallow
wordpress-rest-api
tikz
log4net-configuration
snapkit
angularjs-resource
http-proxy
motherboard
strategy-pattern
mybatis-generator
azure-web-roles
sknode
wicket-tester
aura-framework
php-mongodb
paperclip
amazon-rds-aurora
mef
serialversionuid
critical-section
timex
spring-social-twitter
blitz3d
qudpsocket
paypal-subscriptions
sdkman
redquerybuilder
persian
traminer
uinavigationitem
syncano
web-standards
data-representation
valdr-bean-validation
nsq
caption
drools-guvnor
launcher
api-eveonline
drawable
scjp
visual-studio-setup-proje
lettuce
elixir-framework
imaplib
kademlia
azure-scheduler
proj4
bho
gwt2
qt5.1
idoc
states
beep
flatten
eeprom
facebook-winjs-sdk
datejs
utm
apache-commons-email
rjs
discussion-board
opendir
overlays
norton
fxcopcmd
xcdatamodel
p4.net
managed-code

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile