Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
80
UltraWinGrid Excel export with more than 256 columns
posted

Is there a way to export a WinGrid with more than 256 columns to excel spliting the data into several worksheets?

I tried the following code but I still get an exception:

UltraGridExcelExporter ultraGridExcelExporter = new UltraGridExcelExporter();

ultraGridExcelExporter.FileLimitBehaviour = FileLimitBehaviour.TruncateData;

int columnsCount = m_dataGrid.DisplayLayout.Bands[ 0 ].Columns.Count;

int startColumnIndex = 0;

int worksheetNumber = 1;

Workbook workbook = new Workbook();

while( startColumnIndex < columnsCount )

{

string worksheetNameWithNumber = worksheetName;

if( worksheetNumber > 1 )

worksheetNameWithNumber = String.Format( "{0}_{1}", worksheetName, worksheetNumber.ToString() );Worksheet worksheet = workbook.Worksheets.Add( worksheetNameWithNumber );

ultraGridExcelExporter.Export( m_dataGrid, worksheet, 0, startColumnIndex );

startColumnIndex += 256;

worksheetNumber++;

}

//write to file

BIFF8Writer.WriteWorkbookToFile( workbook, fileName );

 

Thanks,

Santiago Blanco

 

Parents
  • 469350
    Offline posted

     Hi Santiago,

    The problem is with your call to Export. Your code here seems to be making the assumption that the startColumn is the starting column in the grid. It is not. The startColumn is the starting column where the grid will be exported to in the worksheet. So you are basically telling the exporter to start exporting the grid at a column that is outside the valid range. So this method you have here won't work.

    I think what you would have to do here is export the grid multiple times, like you are doing, but rather then specifying the start column in the export method, you will need to hide the grid columns in the layout.

    So you would use the BeginExport event of the UltraGridExcelExporter and hide all of the column in the grid except the ones you want to export to the particular worksheet. So the first time through, you would hide everything after the 256th column. The second time through, you would hide columns 0-255 and then everything above 512

Reply Children