Vijay Jadhav

Vijay Jadhav

  • NA
  • 10
  • 0

C#.NET Windows Write Excel From Last Position

Apr 1 2010 9:34 AM

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.

 


Answers (3)