为什么尝试自动调整 sheet 的宽度或 sheet 上的单个列会失败?
Why does attempting to autofit the width of a sheet, or a single column on that sheet, fail?
我有一列的内容被截断了,我想避免必须双击右侧的列间距才能查看数据。首先,我尝试自动调整整个 shebang:
private void PopulatePivotTableDataSheet()
{
if (null == _produceUsagePivotDataList) return;
AddColumnHeadingRowPivotData();
foreach (ProduceUsagePivotData pupd in _produceUsagePivotDataList)
{
AddPivotData(pupd.ItemCode, pupd.ItemDescription, pupd.Unit, pupd.MonthYear, pupd.Quantity,
pupd.TotalPrice, pupd.IsContractItem);
}
_xlPivotDataSheet.Cells.AutoFit();
}
...但最后一行失败 "AutoFit method of Range class failed"
然后我尝试将它应用于有问题的列,如下所示:
private void AddPivotData(String ItemCode, String ItemDescription, String Unit, String MonthYear, int Quantity, Decimal TotalPrice, Boolean IsContractItem)
{
var itemCodeCell = _xlPivotDataSheet.Cells[_lastRowAddedPivotTableData + 1, 1];
itemCodeCell.Value2 = ItemCode;
var itemDescriptionCell = _xlPivotDataSheet.Cells[_lastRowAddedPivotTableData + 1, 2];
itemDescriptionCell.Value2 = ItemDescription;
itemDescriptionCell.AutoFitWidth();
. . .
...最后一行失败,“'System.__ComObject' 不包含 'AutoFitWidth'”的定义
Sam Hill o' beans 是怎么回事? Autofitting 应该很容易实现,不是吗?
这会将自动调整应用于包含以下范围的列:
_xlPivotDataSheet.Cells.EntireColumn.AutoFit();
我有一列的内容被截断了,我想避免必须双击右侧的列间距才能查看数据。首先,我尝试自动调整整个 shebang:
private void PopulatePivotTableDataSheet()
{
if (null == _produceUsagePivotDataList) return;
AddColumnHeadingRowPivotData();
foreach (ProduceUsagePivotData pupd in _produceUsagePivotDataList)
{
AddPivotData(pupd.ItemCode, pupd.ItemDescription, pupd.Unit, pupd.MonthYear, pupd.Quantity,
pupd.TotalPrice, pupd.IsContractItem);
}
_xlPivotDataSheet.Cells.AutoFit();
}
...但最后一行失败 "AutoFit method of Range class failed"
然后我尝试将它应用于有问题的列,如下所示:
private void AddPivotData(String ItemCode, String ItemDescription, String Unit, String MonthYear, int Quantity, Decimal TotalPrice, Boolean IsContractItem)
{
var itemCodeCell = _xlPivotDataSheet.Cells[_lastRowAddedPivotTableData + 1, 1];
itemCodeCell.Value2 = ItemCode;
var itemDescriptionCell = _xlPivotDataSheet.Cells[_lastRowAddedPivotTableData + 1, 2];
itemDescriptionCell.Value2 = ItemDescription;
itemDescriptionCell.AutoFitWidth();
. . .
...最后一行失败,“'System.__ComObject' 不包含 'AutoFitWidth'”的定义
Sam Hill o' beans 是怎么回事? Autofitting 应该很容易实现,不是吗?
这会将自动调整应用于包含以下范围的列:
_xlPivotDataSheet.Cells.EntireColumn.AutoFit();