Hi Experts,
I am writing excel sheet as a report from C#.NET. (Windows)
My sample snippet is :
Excel.Application excelApp = new Excel.ApplicationClass();
try
{
string workbookPath = "E:\\Read\\DesiredTemplete.xls", CopiedFile =
"E:\\Read\\DesiredTempleteTemp.xls";
FileInfo MyFile = new FileInfo(workbookPath);
FileInfo CopiedFileName = new FileInfo(CopiedFile);
//if (CopiedFileName.Exists)
//{
// CopiedFileName.Delete();
//}
MyFile.CopyTo(CopiedFile);
excelApp.Visible = false;
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(CopiedFile, 0, false, 5,
"", "", false, Excel.XlPlatform.xlWindows, "\t",
false, false, 0, false, false, false);
Excel.Sheets excelSheets = excelWorkbook.Worksheets;
string currentSheet = ConfigurationSettings.AppSettings["ShowExcelSheet"];
Excel.Worksheet excelWorksheet =
(Excel.Worksheet)excelSheets.get_Item(currentSheet);
int iEndRow = 15; int iStartRow = 1;
int iEndCol = 15; int iStartCol = 1;
for (int iRow = 1; iRow < iEndRow; iRow++)
{
for (int iCol = 1; iCol < iEndCol; iCol++)
{
if (((Excel.Range)excelWorksheet.Cells[iRow, iCol]).Value2 != null)
{
for (int iGetValueRow = 0; iGetValueRow <
oDataExcelOutput.Tables[0].Rows.Count; iGetValueRow++)
{
for (int iGetValueColumn = 0; iGetValueColumn < oDataExcelOutput.Tables[0].Columns.Count;
iGetValueColumn++)
{
if (((Excel.Range)excelWorksheet.Cells[iRow, iCol]).Value2.ToString() ==
oDataExcelOutput.Tables[0].Columns[iGetValueColumn].ColumnName)
{
((Excel.Range)excelWorksheet.Cells[iRow, iCol]).Value2 =
oDataExcelOutput.Tables[0].Rows[iGetValueRow][iGetValueColumn].ToString();
break;
}
}
}
}
}
}
Here, I am writting DesiredTempleteTemp from DesiredTemplete.
It displays the report.
It is fine for one person report. If I want to generate report of n person, how should I proceed ?
Here, I want to generate person's report one by one.
Vijay JadhavPosted Apr 6, 2010, 3:40 AM
Please check it at : http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/47ff6a21-88cd-4821-bbb7-d2a0633959bf
Thanks.
Vijay JadhavPosted Apr 2, 2010, 3:30 AM
Thanks for the reply.
I will do the needful.
Thanks.
Jaish MathewsPosted Apr 1, 2010, 1:59 PM
Try to handle through OLEDB provider, if u don't need formats. It's fast as u can use SQLQuery for insertion.