Thank you Kai, Thank you Laurence. But it seems I was not very clear at explaining you my problem.
Here’s the code snippet that I am actually using:
// *******************************************
///
/// This function merges the Data with the Template and
/// sends the formatted output to the client’s browser.
///
/// The Excel Template (without the data)
/// The Data (DataSet) which is to be imported into the Excel file
///
/// The DataSet which holds the StartRow and Start Col positions for each of
/// the DataTables in dsDataToExport DataSet.
///
/// HttpResponse object
private void BeginExport( string strTemplateFile, DataSet dsDataToExport,
DataSet dsSettings, string strSaveAsFile, System.Web.HttpResponse objResponse)
{
try
{
Excel objAsposeExcel = new Excel();
// Open the Excel template
objAsposeExcel.Open(strTemplateFile);
if (dsDataToExport.Tables.Count > 0)
{
for (int intCtr = 0; intCtr < dsDataToExport.Tables.Count; intCtr++)
{
Worksheet objWkSheet = objAsposeExcel.Worksheets[Convert.ToInt32(dsSettings.Tables[intCtr].Rows[0][“intSheetIndex”])];
objWkSheet.Cells.ImportDataTable( dsDataToExport.Tables[intCtr], false,
Convert.ToInt32(dsSettings.Tables[intCtr].Rows[0][“intStartRow”]),
Convert.ToByte(dsSettings.Tables[intCtr].Rows[0][“intStartCol”]), false);
}
objAsposeExcel.Save( strSaveAsFile, SaveType.OpenInBrowser, FileFormatType.Excel2000, objResponse);
}
}
catch(Exception objEx)
{
throw objEx;
}
}
// *******************************************
As you can see above, I have 2 DataSets, one which holds the actual data to be exported, and second which holds the RowStart and ColStart positions where the data in the 1st DataSet should be copied into the Excel file. See the function header comments for more details.
Coming back to my question: I have multiple sheets in my Excel template. Now, let’s assume that I have 2 DataTables in the 1st DataSet and 2 DataTables in the 2nd (for settings), how do I insert data in the 2nd sheet ? I can import data into the 1st sheet successfully, but when I do that for the 2nd, it displays a blank excel file (blank template).
Please see my first message post (one which I had sent on 09-03-2004) for more details.