Re: Problem with export
Data Dynamics Reports Support
Problem with export
03-12-2010, 3:34 AM
I have a problem with exporting reports to other types.
In my reportviewer tool I allow users to hide certain columns in the report. I do this by setting the following property: Table.TableColumns(x).Visibility.Hidden = ExpressionInfo.FromString("True").
I then want to allow the users to export the report to Excel, but when the export happens all the columns that should be invisible are included in the Excel file.
To work around this issue I decided to make a copy of the reportdefinition and edit the copy in such a way that I delete the columns from the table that are invisible in the original reportdefinition. But when I try to make the export work with the copy of the reportdefinition I get the following error: "An unexpected error occured. Additional information: 'Range for report item Table1.Group1 must be within the range for report item Table1'"
I am using a custom toolbar, so I can manipulate the export procedures.
The code I use to make the copy of the reportdefinition is as follows:
Private Sub ExportReport(ByVal def As ReportDefinition)
Dim rpt As String = def.ToRdlString()
Dim data As Byte() = Encoding.UTF8.GetBytes(rpt)
Dim stream As New MemoryStream(data)
Dim expDef As ReportDefinition
Dim reader As New System.IO.StreamReader(stream)
stream.Position = 0
expDef = New ReportDefinition(reader)
For i = 0 To def.Report.Body.ReportItems.Count - 1
If TypeOf def.Report.Body.ReportItems(i) Is Table Then
CType(def.Report.Body.ReportItems(i), Table).TableGroups.Clear()
For ic = CType(def.Report.Body.ReportItems(i), Table).TableColumns.Count - 1 To 0 Step -1
If CType(def.Report.Body.ReportItems(i), Table).TableColumns(ic).Visibility.Hidden = ExpressionInfo.FromString("True") Then
CType(expDef.Report.Body.ReportItems(i), Table).TableColumns.RemoveAt(ic)
End If
Next
End If
Next
Dim reportRuntime As New DataDynamics.Reports.ReportRuntime(expDef)
Dim exportFile As String = ""
Dim dlg As New OpenFileDialog
If dlg.ShowDialog = System.Windows.Forms.DialogResult.OK Then
exportFile = dlg.SafeFileName
Dim myFile As New System.IO.FileInfo(exportFile)
Dim provider As New DataDynamics.Reports.Rendering.IO.FileStreamProvider(myFile.Directory, myFile.Name)
Dim renderingExtension As New DataDynamics.Reports.Rendering.Excel.ExcelTransformationDevice
reportRuntime.Render(renderingExtension, provider)
End Select
End If
End Sub
Re: Problem with export
03-14-2010, 10:57 PM
Hello,
In order to successfully remove the table column using API you need to delete the column cells. F.e. if the table consists of 2 columns, then the code that removes the 2nd column would look like:
Table t = def.Report.Body.ReportItems[0] as Table;
t.TableColumns.RemoveAt(1);
foreach(TableRow tr in t.Details.TableRows)
{
tr.TableCells.RemoveAt(1);
}
If the table has the header, footer and groups headers/footers then the code needs to go through all the rows of each section and remove the column cells, i.e. for the table header rows:
foreach(TableRow trh in t.Header.TableRows)
{
trh.TableCells.RemoveAt(1);
}
As for the issue with the invisible table columns that appear in the xls file, we'll add the change request to address that problem. I'll send the change request number shortly.
Sergey Abakumoff
GrapeCity
Re: Problem with export
03-15-2010, 12:18 AM
Hello,
The change request number for the Excel Export+invisible table column is 144063
Sergey Abakumoff
GrapeCity
Re: Problem with export
03-15-2010, 3:25 AM
Thanks for the response. This really helps me out.