简体   繁体   中英

convert DataGridView Contents to Excel using SpreadSheetLight in C#

so i'm trying to export the contents in a DataGridView to an Excel File. And for me to do this, i am using SpreadSheetLight for C#. But as far as reading the Sample Codes and Tutorials go, they're only demonstrating manual Excel content creation:

using (SLDocument sl = new SLDocument())
{
    sl.SetCellValue("B3", "It costs what for a Jimmy Choo?!?");
    sl.SaveAs("MahNewShoes.xlsx");
}

but what i want to achieve is to convert a whole DataGridView into SpreadSheetLight's Excel. If i am using a loop and loop the whole rows and columns of the DataGridView, how is it possible to set the Columns to A, B, C ... AA, BB, CC given that the loop uses integers ?.

hoping someone can give me a walk through here. thanks

int i= 0;
SLDocument sl = new SLDocument();

foreach (DataRow row in dtTransfer.Rows)
{
  sl[i, 0].SetCellValue("It costs what for a Jimmy Choo?!?");
  sl.SaveAs("MahNewShoes.xlsx");
  i++;
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM