Quantcast
Channel: NPOI
Viewing all articles
Browse latest Browse all 1621

New Post: trying to export column header from DataTable only getting last value

$
0
0
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++;               

            }
        }

Viewing all articles
Browse latest Browse all 1621

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>