Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Thu Jun 03, 2021 1:22 pm

I know you can export a datatable to an Excel file, but can the same be done with data in an asp.net 2.0 gridview?

Is the API compatible with .net 2.0?

Thanks

sconly
 
Posts: 12
Joined: Wed May 08, 2019 10:11 am

Fri Jun 04, 2021 10:59 am

Hi,

Thanks for your inquiry.
Yes, the data of gridview can be exported in Excel too. Please refer to the code below. In addition, Our Spire.XLS has NET2.0, it can work with NET Framework 2.0. If there is any question, please feel free to write back.
Code: Select all
//Get gridview data
object data = this.GridView1.DataSource;
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
//Insert in sheet
sheet.InsertDataTable((DataTable)data, true, 1, 1);     
string result= "output.xlsx";
workbook.SaveToFile(result, ExcelVersion.Version2013);

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1648
Joined: Wed Apr 07, 2021 2:50 am

Fri Jun 04, 2021 11:19 am

Thanks for the reply.

one more thing. I'm using Visual Studio 2005 - no nuget manager- on a Windows 2008 server machine.

Can I still install spire.xls without nuget manager on my PC? If so, how?

Thanks

sconly
 
Posts: 12
Joined: Wed May 08, 2019 10:11 am

Mon Jun 07, 2021 10:19 am

Hello,

Sorry for the late reply on the weekend.
Yes, you can apply our Spire.XLS without nuget. Please download the Spire.XLS Pack Version:11.6 from our website, kindly note this is a msi, please install it on your computer, then you can find the dlls in Bin folder under installing path. Please reference the dlls from NET2.0 in your project. If there is any question, please feel free to write back.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1648
Joined: Wed Apr 07, 2021 2:50 am

Tue Jun 22, 2021 8:20 am

Hello,

Greetings from e-iceblue.
How is your issue going? Did the methods we provided help you? Can you give us some feedback at your convenience? Thanks in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1648
Joined: Wed Apr 07, 2021 2:50 am

Fri Dec 17, 2021 1:05 pm

Sorry for the really late reply, but yes they did help. Thanks.

Although, the dates are exporting/displaying as yyyy-MM-dd but I'd like them to be dd/MM/yyyy or dd-MM-yyyy. Is there anything I can do to achieve this?

Thanks

sconly
 
Posts: 12
Joined: Wed May 08, 2019 10:11 am

Mon Dec 20, 2021 5:48 am

Hello,

Thank you for your response.
Please use the following code to set the display format of the date column.
Code: Select all
//Get gridview data
object data = this.GridView1.DataSource;
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
CellStyle style = workbook.Styles.Add("newStyle");
//Set the display format of the date column
// style. NumberFormat = "dd/MM/yyyy";
style. NumberFormat = "dd-MM-yyyy";
sheet.Columns[0]. CellStyleName = style.Name;
//Insert in sheet
sheet.InsertDataTable((DataTable)data, true, 1, 1);
string result = "output.xlsx";
workbook. SaveToFile(result, ExcelVersion.Version2013);

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1648
Joined: Wed Apr 07, 2021 2:50 am

Thu Dec 23, 2021 7:46 am

Hello,

Hope you are doing well!
How is your issue going? Did the code we provided work for you? Any feedback will be greatly appreciated.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1648
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.XLS