Subject: Excel Application
Posted By: chandler7272 Post Date: 10/3/2005 6:13:45 AM
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.xlWorkbookNormal,null,null,false,false,Excel.XlSaveAsAccessMode.xlShared,false,false,null,null);

                l1.Text = "File Created Successfully!!!";
            }
            catch(Exception Ex)
            {
                
                l1.Text = Ex.Message;
            }    
}


Go to topic 35334

Return to index page 461
Return to index page 460
Return to index page 459
Return to index page 458
Return to index page 457
Return to index page 456
Return to index page 455
Return to index page 454
Return to index page 453
Return to index page 452