How to get named excel sheets while exporting from SSRS

后端 未结 10 1223
粉色の甜心
粉色の甜心 2020-12-08 14:17

Whenever a single page report is exported to excel, sheet in excel is named by the report name. If a report has multiple pages, the sheets are named as sheet1, sheet2,.... I

相关标签:
10条回答
  • 2020-12-08 14:19

    Necromancing, just in case all the links go dark:

    1. Add a group to your report
      Also, be advised to set the sort order of the group expression here, so the tabs will be alphabetically sorted (or however you want it sorted).

      • 'Zeilengruppe' means 'Target group'
      • 'Gruppeneigenschaften' means 'Group properties'
    2. Set the page break in the group properties

      • 'Seitenumbruche' means 'Page break'
      • 'Zwischen den einzelnen Instanzen einer Gruppe' means 'Between the individual instances of a group'
    3. Now you need to set the PageName of the Tablix Member (group), NOT the PageName of the Tablix itselfs.
      If you got the right object, if will say "Tablix Member" (Tablix-Element in German) in the title box of the properties grid. If it's the wrong object, it will say only "table/tablix" (without member) in the property grid's title box.

    4. Note: If you get the tablix instead of the tablix member, it will put the same tab name in every tab, followed by a (tabNum)! If that happens, you now know what the problem is.

    0 讨论(0)
  • 2020-12-08 14:21

    To export to different sheets and use custom names, as of SQL Server 2008 R2 this can be done using a combination of grouping, page breaks and the PageName property of the group.

    Alternatively, if it's just the single sheet that you'd like to give a specific name, try the InitialPageName property on the report.

    For a more detailed explanation, have a look here: http://blog.hoegaerden.be/2011/03/23/where-the-sheets-have-a-name-ssrs-excel-export/

    0 讨论(0)
  • 2020-12-08 14:23

    Put the tab name on the page header or group TableRow1 in your report so that it will appear in the "A1" position on each Excel sheet. Then run this macro in your Excel workbook.

    Sub SelectSheet()
            For i = 1 To ThisWorkbook.Sheets.Count
            mysheet = "Sheet" & i
            On Error GoTo 10
            Sheets(mysheet).Select
            Set Target = Range("A1")
            If Target = "" Then Exit Sub
            On Error GoTo Badname
            ActiveSheet.Name = Left(Target, 31)
            GoTo 10
    Badname:
            MsgBox "Please revise the entry in A1." & Chr(13) _
            & "It appears to contain one or more " & Chr(13) _
            & "illegal characters." & Chr(13)
            Range("A1").Activate
    10
            Next i
    End Sub
    
    0 讨论(0)
  • 2020-12-08 14:32

    To add tab names while exporting to excel, I used the following method:

    • On the report design window, select the tablix object.
    • Open properties window of the tablix object.
    • Add the required tab name to the PageName property.
    • Run the report
    • Export the report to Excel.
    • Now the worksheet name is the same as the PageName property of the tablix object.
    0 讨论(0)
  • 2020-12-08 14:40

    There is no direct way. You either export XML and then right an XSLT to format it properly (this is the hard way). An easier way is to write multiple reports with no explicit page breaks so each exports into one sheet only in excel and then write a script that would merge for you. Either way it requires a postprocessing step.

    0 讨论(0)
  • 2020-12-08 14:40

    You could use -sed- and -grep- to replace or write to the xml header of each file specifying your desired sheet name, e.g., sheetname1, between any occurrence of the tags:

    <Sheetnames>?sheetname1?</Sheetnames>
    
    0 讨论(0)
提交回复
热议问题