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

lambda innerjoin convert error
Matrix Multiplication with threads
Send XML file on request
Load a function after the layout is being added and shown completely
Updating the key object in AddOrUpdate method
ObjectDisposedException while using socket
How can I add a text box dynamically under an other by pressing a button in c#? (winforms)
VS2013 Dynamically create chart c#
.UpdateLayout() throwns an exception from RunWorkerCompleted method
Unix to Dos Conversion in C#
How to fill a textbox by using another textbox textchanged event?
NHibernate How do i put data in many to many mapping
Is there a way to use the Windows Form table in a Razor view cshtml?
Round robin pub/sub with StackExchange.Redis
Check if 'Restrict background data' is active on Windows Phone
XMLHttpRequest: Network Error Access is denied

Categories

HOME
repository
stanford-nlp
ssh
packet
singleton
xss
grid
foreach
opacity
rtc
obd-ii
subprocess
cracking
jcodemodel
versioning
ringcentral
airbnb
openoffice-basic
rndis
screen-scraping
email-client
apdu
mongoose-im
azure-table-storage
spring-data-gemfire
jmsserializerbundle
akamai
wordpress-rest-api
jsonapi-resources
rythm
mongoid5
jslider
definition
qt-quick
superclass
chrome-custom-tabs
ng-class
vertex
visualizer
bioperl
node-java
nsalert
dynatable
qt3d
blitz3d
eclipse-mars
konakart
normalisation
gdi
django-celery
python-rq
mod
web-optimization
stdlist
nugetgallery
jsondoc
ewam
skscene
maven-antrun-plugin
openhab
eggplant
photogrammetry
esb-toolkit-2.1
esri-arc-engine
crtdbg.h
iphone-6
kss
register-allocation
go-gin
vundle
telerik-appbuilder
sigma-grid-control
iwork
acrofields
kernel-density
android-jack-and-jill
ekevent
google-oauth-java-client
scidb
typography
select2-rails
mysql2
libx264
linear-interpolation
big-endian
event-propagation
mvcmailer
yii-cactiverecord
virtual-printer
rjs
discussion-board
flexbuilder
overlays
jquery-click-event
youtube.net-api
zipstream
noise-reduction
viewdata
text-manipulation
code-golf
helios
dynamic-scope
pkcs#7
data-formats
vista64

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App