1

I am creating an Excel using DataTable. My requirement is to skip first two columns and populate values from third column. When I try to add column with string.Empty, it creates Column1,Column2 in Excel.

As per link https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/dataset-datatable-dataview/adding-columns-to-a-datatable , it auto generates Column1. But somehow I need to skip first two Columns.

Can someone help me to achieve this.

var myDataSet = new DataSet();
var table = myDataSet.Tables.Add("ProductDetails");

table.Columns.Add(string.Empty);
table.Columns.Add(string.Empty);
table.Columns.Add("ID");
table.Columns.Add("Name");
table.Columns.Add("Code");
table.Columns.Add("Price");

Current output in Excel:

enter image description here

Expected output:

enter image description here

Tech Learner
  • 1,227
  • 6
  • 24
  • 59
  • 1
    Try giving them a name like " " (single space) though my guess is whatever you see using is turning all whitespace names into non-whitespace – pinkfloydx33 May 20 '20 at 12:51
  • You haven't shown how you write that data to Excel, but I assume you are using OLE DB or something. You may need to use a different method, like the Open XML SDK to create the spreadsheet. – Crowcoder May 20 '20 at 12:52
  • @pinkfloydx33 - Single space works perfectly. Thanks! – Tech Learner May 20 '20 at 13:10

0 Answers0