Excel Application
I have an application whr i pass around 300000 values to the below method to genarate the output in an excel file.. problem is my code is giving the output only for the last input alone.... plz help me in solving this........
thanks to u all in advance.......
private void GetHospitals(int[] RecordNumbers)
{
DataTable HospitalDataTable = Map1.Layers["hospital"].DataQuery(RecordNumbers, true);
HospitalDataTable.Columns.Add("ZipCode");
int[] ZipRecordNumbers = new int[0];
foreach (DataRow record in HospitalDataTable.Rows)
{
ZipRecordNumbers = Map1.Layers["zip_poly"].SpatialQuery((BaseShape)record["MapSuiteShape"], MapSuite.SpatialQueryContainment.Contained);
record["ZipCode"] = Map1.Layers["zip_poly"].DataQuery(ZipRecordNumbers[0], "ZIP");
}
try
{
string dstfile= "c:\\HospitalZipcodeList.xls";
Excel.Application excel= new Excel.Application();
Excel._Worksheet wsheet;
Excel._Workbook wbook;
excel.Visible=false;
int rowIndex=1;
int colIndex=0;
wbook =(Excel._Workbook)(excel.Workbooks.Add(true));
wsheet=(Excel._Worksheet)wbook.ActiveSheet;
//excel.Application.Workbooks.Add(true);
//DataTable table=new DataTable();
foreach(DataColumn col in HospitalDataTable.Columns)
{
colIndex++;
wsheet.Cells[1,colIndex]=col.ColumnName;
}
foreach(DataRow row in HospitalDataTable.Rows)
{
rowIndex++;
colIndex=0;
foreach(DataColumn col in HospitalDataTable.Columns)
{
colIndex++;
wsheet.Cells[rowIndex,colIndex]=row[col.ColumnName].ToString();
}
}
excel.Visible=true;
wbook.SaveAs(dstfile,Excel.XlFileFormat.xlWorkbook Normal,null,null,false,false,Excel.XlSaveAsAccessM ode.xlShared,false,false,null,null);
l1.Text = "File Created Successfully!!!";
}
catch(Exception Ex)
{
l1.Text = Ex.Message;
}
}
|