Naming sheets using Asp.net SSRS 2008 (RDLC) to export to Excel

I am working on a VSX asp.net VS 2008 application where it contains an existing RDLC (client file and NOT server side RDL file ).

The problem is export to excel, all worksheets are not named properly i.e. Sheet1, Sheet2, etc. I found many examples when exporting data, in SQL Server 2008 R2, RDL functions, however I need an RDLC solution ?

Does anyone know how to "fix" this, or do some kind of posting to rename the tabs so that the client doesn't end up seeing Sheet1, Sheet2, Sheet3, etc.?

  • Application chooses path to RDLC file
  • Adds DataSource
  • Selects xls
  • All Answers

I see this Stackoverflow link How to get the names of excel sheets when exporting from SSRS :

  • Unable to execute macro
  • Unable to export as SSML
  • I am NOT using SSRS RDL / SQL Server 2008 R2 , so the other answers are misleading for people using RDLC
+1


source to share


3 answers


Renaming sheets is not supported by the RDLC version of the report. I am guessing that you cannot update. So here's the job: Save the report to file as usual. Then open it again using Microsoft.Office.Interop.Excel or any other Excel library to rename the sheets. Once you've done that, save and you're done.

using Excel = Microsoft.Office.Interop.Excel; 


Excel.ApplicationClass xl=new Excel.ApplicationClass();
    Excel.Workbook xlBook;
    Excel.Worksheet xlSheet;
    string filePath = Server.MapPath(@"\report.xls");
    xlBook = (Workbook)xl.Workbooks.Open(filePath,Type.Missing,
      Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing
     ,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing);
    xlSheet = (Worksheet)xlBook.Worksheets.get_Item(1);
    xlSheet.Name = "New Sheet Name";
    xlBook.Save();
    xl.Application.Workbooks.Close();

      



A list of various libraries you can use if this doesn't work for you: Free Libraries 1. Close XML Library - http://closedxml.codeplex.com/documentation  2. Open XML SDK - http://msdn.microsoft.com /en-us/library/bb448854.aspx  3. NOPI - http://npoi.codeplex.com/  4. CarlosAG - http://www.carlosag.net/Tools/ExcelXmlWriter/

Paid Libraries 5. Spreadsheet Engine 6. Smart XLS 7. Office Writer 8. Spire

+2


source


I would upgrade to RDL 2010 schema - it supports Excel Named Sheets (among other useful improvements):



http://msdn.microsoft.com/en-us/library/ee960138.aspx

0


source







All Articles