使用 C# VSTO 在 Excel 中设置列宽
Setting Columns Width in Excel with C# VSTO
我正在为 VSTO 使用 C# Excel 添加。
目前我正在将列设置为自动安装:
newWorkSheet.Columns.AutoFit();
如何设置列宽以增加一些填充?
在伪代码中它将是:
Column.Width = columnCurrentWidth + 10
对于某一列,使其比自动适应宽度稍宽
我已经弄清楚如何获取列宽但未设置它
int width = ((Excel.Range)newWorkSheet.Cells[rowCount, 2]).Width;
您必须设置 ColumnWidth
和 RowHeight
共 Range
。
这应该有效:
int width = ((Excel.Range)newWorkSheet.Cells[rowCount, 2]).Width;
((Excel.Range)newWorkSheet.Cells[rowCount, 2]).ColumnWidth = width + 10;
我正在为 VSTO 使用 C# Excel 添加。
目前我正在将列设置为自动安装:
newWorkSheet.Columns.AutoFit();
如何设置列宽以增加一些填充?
在伪代码中它将是:
Column.Width = columnCurrentWidth + 10
对于某一列,使其比自动适应宽度稍宽
我已经弄清楚如何获取列宽但未设置它
int width = ((Excel.Range)newWorkSheet.Cells[rowCount, 2]).Width;
您必须设置 ColumnWidth
和 RowHeight
共 Range
。
这应该有效:
int width = ((Excel.Range)newWorkSheet.Cells[rowCount, 2]).Width;
((Excel.Range)newWorkSheet.Cells[rowCount, 2]).ColumnWidth = width + 10;