Skip to content
Loading
  • 0
    Amit
     
    where do I place that in my code or what do I replace?
    getting build error.
     
    Thanks 
    0
  • Amit Gupta
    0
    You can write above the for loop
    0
  • 0
    I spoke wrong this is what i need to do without having to save the file.
     
    The below code when exporting to excel gives the Book name Book1. How can i edit it to export the Book name as "Sams Report"?
    0
  • Amit Gupta
    0
    Then you have to set the title of the excel application, this will gives you the expected filename when saving
    0
  • 0
    I'd suggest you use a free third party library free Spire.XLS to export data to excel, it's easy and doesn't rely on Excel. You can get free Spire.XLS dll from NuGet Package Manager and refer to the following code:
    1. DataTable dt = dataGridView1.DataSource as DataTable;  
    2. Workbook workbook = new Workbook();  
    3. Worksheet sheet = workbook.Worksheets[0];  
    4. sheet.Name = "Sams Report";  
    5. sheet.InsertDataTable(dt, true, 1, 1);  
    6. workbook.SaveToFile("Report.xlsx", ExcelVersion.Version2013);  
    0
  • 0
    You will need to get reference to the active sheet and set a name to it.
     
    Microsoft.Office.Interop.Excel.Workbook workBook;
    Microsoft.Office.Interop.Excel.Worksheet workSheet;
     
    workBook = XcelApp.Application.Workbooks.Add(Type.Missing);
    workSheet = (Microsoft.Office.Interop.Excel.Worksheet) workBook.ActiveSheet;
    workSheet.Name = "Sams Report";
    0
  • 0
    ZetExcel is a great SDK product is a flexible platform all in C# and super well suited for .NET applications
    0
  • 0
    workSheet = (Microsoft.Office.Interop.Excel.Worksheet) workBook.ActiveSheet;
    workSheet.Name = "Sheet name";
    0