Naming of Sheets using Asp.net SSRS 2008 (RDLC) for export to Excel

不问归期 提交于 2019-12-08 04:03:25

Sheet renaming isn't supported with the version of RDLC report. I'm guessing you can't upgrade. So here's a work around: Save the report to a file as normal. Then open it again using Microsoft.Office.Interop.Excel or any other Excel library to rename the sheets. Once you do this 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();

List of different libraries that you can use if this one 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 Gear 6. Smart XLS 7. Office Writer 8. Spire

I would upgrade to the RDL 2010 schema - it supports Excel Named Sheets (amongst other useful enhancements):

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!