0

I need to take the content of a C# datatable and deposit it (...) in a new Excel spreadsheet. I have seen some good generic code to do this, however, my problem is that I need to be specific, column by column, as to the format of the cells. For example, I need to enforce a rule that certain columns are TEXT only - so that numbers (without leading text) are NOT treated as numeric values.

Typically, when Excel sees '01', it will load the cell as '1' with the leading zero truncated, and, further, right justified as numeric data would be. However, in my example, this would be incorrect, since '01' is a STRING and not a number, and must, therefore, retain the "leading" zero and be left justified.

Therefore, how do I go about specifying the data types for columns in a spreadsheet generated from a C# datatable?

Thanks.

Avrohom

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Momerath
0

You do something along these lines

Range rg = worksheet.get_Range("A1","E1");
rg.Select();
rg.Font.Bold = true;
rg.Font.Name = "Arial";
rg.Font.Size = 8;
rg.WrapText = true;
rg.HorizontalAlignment = Excel.Constants.xlCenter;
rg.Interior.ColorIndex = 6;
rg.Borders.Weight = 3;
rg.Borders.LineStyle = Excel.Constants.xlSolid;
rg.Cells.RowHeight = 38;
0

It's a good answer, but not what I'm trying to do. I need to make specific columns to act as TEXT.

0

It is what you are trying to do. NumberFormat = "@".

Sometimes you need to look for the answer, instead of waiting for it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.