My sqldatareader is returning ~200 rows of data. About half of those rows have a column that contains an entire xml document. I'm assuming this column is causing the autofit() method to hang. How can I go about getting this to either throw an exception, or complete successfully. I don't care which one, I just need this [automated] program to finish.
Excel.Application xl = null;
Excel._Workbook wb;
Excel._Worksheet ws;
try
{
xl = new Microsoft.Office.Interop.Excel.Application();
xl.Visible = false;
while (reader.HasRows && !done)
{
wb = (Excel._Workbook)(xl.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet));
ws = (Excel._Worksheet)wb.ActiveSheet;
// Insert column headers
for (int counter = 0; counter < reader.FieldCount; counter++)
ws.Cells[1, counter + 1] = reader.GetName(counter);
// Write the data to the excel file
while (reader.Read())
{
for (int counter = 1; counter <= reader.FieldCount; counter++)
{
// Need to format this column so excel doesn't change how it looks
if (report.ReportName == "RPTAAMVANetBatch" && reader.GetName(counter - 1) == "CorrelationID")
ws.Cells[rowCounter, counter] = String.Format("''{0}'", reader.GetValue(counter - 1));
else
ws.Cells[rowCounter, counter] = reader.GetValue(counter - 1);
}
rowCounter++;
}
RecordsProcessed = rowCounter - 1;
// Format the excel file to liking
ws.get_Range(ws.Cells[1, 1], ws.Cells[rowCounter - 1, reader.FieldCount]);
ws.Columns.AutoFit();