【问题标题】:Syntax for Excel Object. Change Number FormattingExcel 对象的语法。更改数字格式
【发布时间】:2012-03-22 16:21:20
【问题描述】:

我制作了一个应用程序,可以将 SQL Select 中的记录提取到 Excel。
我想在保存之前更改 excel 列的数字格式。我制作了 EXCEL OLE 对象,然后将数据写入它

Excel_Sheet.Cells[i + j,k] =  s_col

我想根据列类型更改数字格式。我已经知道如何获取列类型,但无法更改数字格式。

我使用了这些:使标题加粗并根据使用 AutoFit 的数据更改宽度。我在互联网上找到的所有内容:

Excel_Sheet.Range(s_into_row + String(j) + ":" +s_into_col + String(j)).Select
Excel_Obj.Selection.Font.Bold = True

Excel_Sheet.Range("A"+String(j)+":A"+String(j)).Select
Excel_Sheet.Columns(s_into_row + ":" + s_into_col ).EntireColumn.AutoFit

我正在使用 powerbuilder

【问题讨论】:

  • 我没有和 Powerbuilder 合作过,但你有没有尝试过类似Excel_Sheet.Columns(s_into_row).NumberFormat = "0.00"
  • 嘿,它奏效了,没想到这么简单。感谢您的回答,我知道 pb 无关紧要,但我只是尝试提及它。非常感谢先生。我如何将您的答案标记为正确:D 再次感谢
  • @SiddharthRout:可以发布答案,以便 Sid 接受。解决方案的功劳属于您 :)

标签: sql excel extract powerbuilder vba


【解决方案1】:

我没有与 Powerbuilder 合作过,但你有没有尝试过类似的东西

Excel_Sheet.Columns(s_into_row).NumberFormat = "0.00"

【讨论】:

    【解决方案2】:

    我在一个项目中有一些类似这样的代码:

    choose case lower(ls_coltype)
        case "char"
            lole_Excel.Selection.NumberFormat = "@"
        case "date"
            lole_Excel.Selection.NumberFormat = "mm/dd/yyyy"
        case "int", "long", "ulong"
            lole_Excel.Selection.NumberFormat = "0"
        case "time"
            lole_Excel.Selection.NumberFormat = "h:mm AM/PM"
        ...
    end choose 
    

    其中 ls_coltype 是带有“(”的列类型以及删除后的所有内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多