以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  报表 用千位符  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=143456)

--  作者:fubblyc
--  发布时间:2019/11/25 17:27:00
--  报表 用千位符
    Dim Book As New XLS.Book \'定义一个Excel工作簿

        t.CreateSheetHeader(Sheet,2,0,True) \'生成表头
        Dim hdr As Integer = t.HeaderRows \'获得表头的层数
        Dim cnt As Integer = 0
        For c As Integer = 3 To 4 + 15 - 1            
            If t.Cols(c).Visible Then
                For r As Integer = 0 To t.Rows.Count - 1
                    If CStr(t(r,c)) <> "0" Then
                        sheet(r + hdr+2,cnt).value = t(r,c)
                    End If
                Next
                cnt = cnt + 1
            End If
        Next

老师,上述代码,写出来的值,想要用千位符来显示,要怎么处理呢


图片点击可在新窗口打开查看此主题相关图片如下:微信截图_20191125172517.png
图片点击可在新窗口打开查看

[此贴子已经被作者于2019/11/25 17:30:21编辑过]

--  作者:有点蓝
--  发布时间:2019/11/25 17:34:00
--  
参考:http://www.foxtable.com/webhelp/topics/0361.htm

sheet(r + hdr+2,cnt).value = format(t(r,c),............

--  作者:fubblyc
--  发布时间:2019/11/25 17:58:00
--  
老师,我这样试了:
                        If c = 3 Then
                            sheet(r + hdr+2,cnt).value = t(r,c)
                        ElseIf  c = 9 Or c = 14 Then
                            sheet(r + hdr+2,cnt).value = format(t(r,c),"Percent")
                        Else
                            sheet(r + hdr+2,cnt).value = format(t(r,c),"n")                            
                        End If
是可以显示,但是都是变成文本型的:

图片点击可在新窗口打开查看此主题相关图片如下:微信截图_20191125175741.png
图片点击可在新窗口打开查看
有左上角那个符号,密密麻麻的,有办法不显示那个吗


--  作者:有点蓝
--  发布时间:2019/11/25 20:13:00
--  
那样设置样式了:http://www.foxtable.com/webhelp/topics/1165.htm


NumberFormat

单元格格式是通过NumberFormat或NumberFormatLocal属性来完成的。例如:

Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("D:\\Report.xls")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Ws.Range("A1").NumberFormat = "G/通用格式" \'通用格式
Ws.Range("B1").NumberFormat = "0_ "   \'数值
Ws.Range("C1").NumberFormat = "#,##0.00_);[红色](#,##0.00)" \'货币
Ws.Range("D1").NumberFormat = "_ * #,##0.00_;_ * -#,##0.00_ ;_ * ""-""??_ ;_ @_ " \'会计专用
Ws.Range("E1").NumberFormat = "yyyy-m-d" \'日期
Ws.Range("F1").NumberFormat = "h:mm:ss"  \'时间
Ws.Range("G1").NumberFormat = "0.00%"    \'百分比
Ws.Range("H1").NumberFormat = "# ?/?"    \'分数
Ws.Range("I1").NumberFormat = "0.00E+00" \'科学记数
Ws.Range("J1").NumberFormat = "@"   \'文本
App.Visible = True

--  作者:fubblyc
--  发布时间:2019/11/26 8:36:00
--  
可以,搞定了。谢谢蓝大神
--  作者:fubblyc
--  发布时间:2019/12/2 17:20:00
--  
老师,那这种呢?看了帮助没有找到直接相关的....

Dim rt As New prt.RenderTable \'定义一个新表格
Dim tb As Table = Forms("预算表").Controls("table1").Table
Dim ColNames As String() = New String(){"项目", "A00", "C00","总计","备注"}
rt.Width = "Auto" \'表格宽度为自动,也就是等于各列设置宽度之和
rt.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded \'表格宽度超出页宽时,可以水平换页
rt.Style.Font = New Font("微软雅黑", 6.35) \'设置文本对象的字体

For c As Integer = 0 To ColNames.Length - 1 \'逐列设置和填入内容
    rt.Cells(0,c).Text = ColNames(c) \'列名作为标题
    rt.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'标题内容水平居中
    rt.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth \'列宽等于实际列宽
    If tb.Cols(ColNames(c)).IsNumeric OrElse tb.Cols(ColNames(c)).IsDate Then \'如果是数值或日期列
        rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Right \'数据水平靠右
这里再设置一个 用千位符 表示的格式
    End If


--  作者:有点蓝
--  发布时间:2019/12/2 17:35:00
--  
这里直接使用format
--  作者:fubblyc
--  发布时间:2019/12/2 17:40:00
--  
哦哦,知道了,谢谢老师
[此贴子已经被作者于2019/12/2 17:40:52编辑过]