BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
Hi Pradeep,
Sorry for delay in replying to the query. I have found the root
cause for the issue.
In earlier versions of Excel(before 2007), the column count in worksheet is limited to 256. This exception might occur when more than 256 columns are exported to an excel sheet of old versions( before 2007).Hence you cannot export columns above that count from grid to an excel sheet in earlier versions. Only in Excel 2007, support to export more than 256 columns has been provided.
Please refer to the following link where it has been illustrated.
To convert the grid content to an excel sheet of .xlsx format, you have to explicitly set the ExcelVersion by creating an XlsIO application and exporting the grid contents to its sheet. Here is the code handled to export for your reference.
ExcelEngine engine = new ExcelEngine();
IApplication app = engine.Excel.Application;
app.DefaultVersion =
ExcelVersion.Excel2007;
IWorkbook book = app.Workbooks.Create();
GroupingGridExcelConverterControl gecc = new
GroupingGridExcelConverterControl();
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Files(*.xlsx)|*.xlsx";
saveFileDialog.DefaultExt = ".xlsx";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
gecc.GroupingGridToExcel(this.gridGroupingControl1,
book.Worksheets[0], ConverterOptions.Visible);
book.SaveAs(saveFileDialog.FileName);
if (MessageBox.Show("Do you wish to open the xls file
now?", "Export to Excel", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
{
Process proc = new Process();
proc.StartInfo.FileName = saveFileDialog.FileName;
proc.Start();
}
}
I have reproduced the issue in the attached by replacing the above highlighted code by the following code:
app.DefaultVersion = ExcelVersion.Excel97to2003;
Exception(Stack Trace):
System.ArgumentOutOfRangeException was unhandled
Message=Specified argument was out of the range of valid
values.
Source=Syncfusion.XlsIO.Base
StackTrace:
at
Syncfusion.XlsIO.Implementation.RangeImpl.CheckRange(Int32 row, Int32 column)
at
Syncfusion.XlsIO.Implementation.RangeImpl.get_Item(Int32 row, Int32 column,
Int32 lastRow, Int32 lastColumn)
at
Syncfusion.GroupingGridExcelConverter.GroupingGridExcelConverterControl.ExportEmptyCells(IWorksheet
sheet, Int32 index, ConverterOptions options, GridTableCellStyleInfo style,
Int32 iColumnCount, Int32 iGroupLevel)
at
Syncfusion.GroupingGridExcelConverter.GroupingGridExcelConverterControl.ExportElements(IList
arrElements, IWorksheet sheet, Int32 index, ConverterOptions options, Int32
iGroupLevel)
at
Syncfusion.GroupingGridExcelConverter.GroupingGridExcelConverterControl.GroupingGridToExcel(GridGroupingControl
grouping, IWorksheet sheet, ConverterOptions options)
at
I62024.Form1.btnExport_Click(Object sender, EventArgs e) in
c:\Users\Administrator\Downloads\Sample1570834182\Sample\Form1.cs:line 51
at
System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs
mevent)
at
System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button,
Int32 clicks)
at
System.Windows.Forms.Control.WndProc(Message& m)
at
System.Windows.Forms.ButtonBase.WndProc(Message& m)
at
System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at
System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at I62024.Program.Main() in
c:\Users\Administrator\Downloads\Sample1570834182\Sample\Program.cs:line 17
at
System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at
System.Threading.ExecutionContext.Run(ExecutionContext executionContext,
ContextCallback callback, Object state)
at
System.Threading.ThreadHelper.ThreadStart()
InnerException:
Here is the sample which exports grid to a .xlsx format sheet which supports large number of
columns.
Sample: http://www.syncfusion.com/downloads/support/directtrac/112508/Excel_Export702510096.zip
Please let me know if you have any concerns.
Regards,
Athiram S