This project is read-only.

trying to export column header from DataTable only getting last value

Jan 28, 2015 at 8:35 PM
I am trying to loop though a data table of headers. It is only writing the last one.
Any idea why?
//set the workbook properties and add a default sheet in it
                IWorkbook workBook = new XSSFWorkbook();
                ISheet worksheet1 = workBook.CreateSheet("Transactions");                

               DataTable columnHeader = new DataTable("Header");
                columnHeader.Columns.Add("a", typeof(String));
                columnHeader.Columns.Add("b", typeof(String));
                columnHeader.Columns.Add("c", typeof(String));
                columnHeader.Columns.Add("d", typeof(String));
                columnHeader.Columns.Add("e", typeof(String));
                columnHeader.Columns.Add("f", typeof(String));
                columnHeader.Columns.Add("g", typeof(String));
                columnHeader.Columns.Add("h", typeof(String));
                columnHeader.Columns.Add("i", typeof(String));
                columnHeader.Columns.Add("j", typeof(String));
                columnHeader.Columns.Add("k", typeof(String));
                columnHeader.Columns.Add("l", typeof(String));
                columnHeader.Columns.Add("m", typeof(String));
                columnHeader.Columns.Add("n", typeof(String));
                columnHeader.Columns.Add("o", typeof(String));
                columnHeader.Columns.Add("p", typeof(String));
                columnHeader.Columns.Add("q", typeof(String));
                columnHeader.Columns.Add("r", typeof(String));
                columnHeader.Columns.Add("s", typeof(String));
                columnHeader.Columns.Add("t", typeof(String));
                int rowIndex = 0;
                CreateHeader(worksheet1, ref rowIndex, columnHeader);


 private static void CreateHeader(ISheet worksheet1, ref int rowIndex, DataTable dt)
        {
            int colIndex = 1;
            IRow row = worksheet1.CreateRow(rowIndex);

            foreach (DataColumn dc in dt.Columns) //Creating Headings
            {
                
                worksheet1.CreateRow(rowIndex).CreateCell(colIndex).SetCellValue(dc.ColumnName.ToString()); 
                colIndex++;               

            }
        }
Jan 28, 2015 at 8:47 PM
even more odd a simple thing like this only creates the last one in header.

worksheet1.CreateRow(0).CreateCell(1).SetCellValue("a");
worksheet1.CreateRow(0).CreateCell(2).SetCellValue("b");
worksheet1.CreateRow(0).CreateCell(3).SetCellValue("c");