Reg: not able to convert the Format Cell=text by programatically

  • Thread starter lpv kumar Gullapalli
  • Start date
L

lpv kumar Gullapalli

I have written a code to Export the data from DataTable to Excel File. this
is code working fine.However, i need the Format cells=Text. The entire work
sheet should appear in Text. even when a number is inthe cell it should be
treated a Text. plz give me necessary solutions for this Code snippet.
public static void GenerateReport(DataTable exportData)
{

Excel.Application objExcel = new Excel.ApplicationClass();

objExcel.Application.Workbooks.Add(true);
objExcel.Visible = true;

objExcel.ActiveCell.NumberFormat = objExcel.ActiveCell.Text;
objExcel.Cells.NumberFormat = objExcel.Cells.Text;

int ColumnIndex = 0;
foreach (DataColumn dCol in exportData.Columns)
{
ColumnIndex++;
objExcel.Cells[1, ColumnIndex] = dCol.ColumnName;

}

int rowIndex = 0;
foreach (DataRow dr in exportData.Rows)
{
rowIndex++;
ColumnIndex = 0;
foreach (DataColumn rcol in exportData.Columns)
{
ColumnIndex++;
objExcel.Cells[rowIndex + 1, ColumnIndex]
=dr[rcol.ColumnName];
}
}
objExcel.Visible = true;

Excel.Worksheet worksheet =
(Excel.Worksheet)objExcel.ActiveSheet;

worksheet.Activate();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top