'Set Column Width in C# (Interop.Excel) could be too larger
I counldn't set the width with Interop.
My code is :
double kA = ((Excel.Range)st.Columns[1]).EntireColumn.Width;
double kB = ((Excel.Range)st.Columns[2]).EntireColumn.Width;
int KNA = Convert.ToInt32(kA + kB);
//((Excel.Range)st.Columns[1]).EntireColumn.ColumnWidth = kA + kB;
Console.WriteLine(KNA);
((Excel.Range)st.Columns[1]).ColumnWidth = KNA;
Console.WriteLine(((Excel.Range)st.Columns[1]).EntireColumn.Width);
((Excel.Range)st.Columns[2]).EntireColumn.Delete();
Both kA and kB is 59.25,and KNA is 118.But the actual width of Column A is 801.75,and it couldn't be modified any way. I use ((Excel.Range)st.Columns1).ColumnWidth = KNA; But the columnA width couldn't be change. What's wrong?
I tried to change the initial columnWidth of column A&B,and I got the different value of new column width but is still more larger than KNA,about 6.8 times each time.
Solution 1:[1]
I use columnWith to get and set columnwidth,and It's OK.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ??? |


