【问题标题】:Format vsto listobject before linked to datatable在链接到数据表之前格式化 vsto listobject
【发布时间】:2018-02-14 06:03:51
【问题描述】:

我有一个填充 Excel 工作表的 vsto 应用程序。

首先我填充数据表。下一个函数是创建一个 vsto 列表对象:

// Populate the sheet
XlsInterop.Excel.Worksheet worksheet = (XlsInterop.Excel.Worksheet)Globals.ThisAddIn.Application.ActiveWorkbook.Worksheets.Add();
extendedWorksheet = Globals.Factory.GetVstoObject(worksheet);
XlsInterop.Excel.Range cell = extendedWorksheet.Range["A1"];


excelItemsList = extendedWorksheet.Controls.AddListObject(cell, sheetName);
excelItemsList.AutoSetDataBoundColumnHeaders = true;
excelItemsList.DataSource = dt;
excelItemsList.ListColumns[5].Range.NumberFormat = "@";

现在的问题是,在“5”列中,我有 005、004 之类的值。在 Excel 中,这些值显示为 5 和 4。如何确保 Excel 中的值显示与我的数据库中相同的值?

如果我像这样更改代码:

excelItemsList.SetDataBinding(dt);
excelItemsList.ListColumns[5].Range.NumberFormat = "@";
excelItemsList.SetDataBinding(dt);

它正在做我想做的事,但我不认为这是要走的路。

【问题讨论】:

  • 您还有格式问题吗?

标签: c# vsto


【解决方案1】:

如果您知道需要多少个前导零,则可以用它来格式化列。

.NumberFormat = "000";

该列仍将被评估为一个数字。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-10
    • 1970-01-01
    • 2019-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-28
    • 1970-01-01
    相关资源
    最近更新 更多