以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  交叉统计表“abc表” 输出到excel,如何设置excel单元格的宽度、高度  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=89210)

--  作者:wangjh8888
--  发布时间:2016/8/17 11:55:00
--  交叉统计表“abc表” 输出到excel,如何设置excel单元格的宽度、高度
采用下列代码把一交叉统计表“abc表” 输出到excel,如何设置excel单元格的宽度、高度

Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog
dlg.Title="请选择保存文件"
dlg.InitialDirectory=ProjectPath & "Reports\\"
dlg.Filter= "Excel文件|*.xls" \'设置筛选器
dlg.FileName="test"

If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮
    
    Dim flg As New SaveExcelFlags
    \'flg.RowNumber = True
    flg.CellStyle = True
    
    Tables("abc表").SaveExcel(dlg.FileName, "abc表",flg)  \'保存文件
End If

--  作者:大红袍
--  发布时间:2016/8/17 12:16:00
--  

 可以在表里面设置好宽高,再saveExcel

 

Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog
dlg.Title="请选择保存文件"
dlg.InitialDirectory=ProjectPath & "Reports\\"
dlg.Filter= "Excel文件|*.xls" \'设置筛选器
dlg.FileName="test"


If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮
   
    Dim flg As New SaveExcelFlags
    \'flg.RowNumber = True
    flg.CellStyle = True
   
    Tables("abc表").grid.Rows(2).Height = 100
    Tables("abc表").Grid.Cols("第二列").width = 300

   
    Tables("abc表").SaveExcel(dlg.FileName, "abc表",flg)  \'保存文件
End If


--  作者:wangjh8888
--  发布时间:2016/8/17 13:10:00
--  
由于交叉统计表列数不定,如何设定所有列宽和所有行高
--  作者:大红袍
--  发布时间:2016/8/17 14:28:00
--  

比如,代码

 

Tables("表A").DefaultRowHeight = 50
Tables("表A").DefaultColWidth = 100


--  作者:wangjh8888
--  发布时间:2016/8/18 15:31:00
--  
谢谢   就是要这效果
--  作者:wangjh8888
--  发布时间:2016/8/18 15:34:00
--  
柔柔问下  这些单元格框线要加粗 怎么弄?


--  作者:大红袍
--  发布时间:2016/8/18 15:43:00
--  
Tables("表A").grid.styles.Normal.Border.Color = Color.Red
Tables("表A").grid.styles.Normal.Border.Style = 1
Tables("表A").grid.styles.Normal.Border.width = 5
Tables("表A").grid.styles.Normal.Border.Direction = 0 \'0-2

--  作者:wangjh8888
--  发布时间:2016/8/18 16:09:00
--  
    Tables("表A").grid.styles.Normal.Border.Color = Color.Red
    Tables("表A").grid.styles.Normal.Border.Style = 1
    Tables("表A").grid.styles.Normal.Border.width = 2
    Tables("表A").grid.styles.Normal.Border.Direction = 0 \'0-2
    
    Tables("表A").SaveExcel(dlg.FileName, "表A",flg)  \'保存文件


放在saveexcel之前吗   怎么没有出效果?!

--  作者:大红袍
--  发布时间:2016/8/18 17:08:00
--  

 比较麻烦,先试试,不行就用vba处理

 

Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog
dlg.Title="请选择保存文件"
dlg.InitialDirectory=ProjectPath & "Reports\\"
dlg.Filter= "Excel文件|*.xls" \'设置筛选器
dlg.FileName="test"


If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮
   
    Dim flg As New SaveExcelFlags
    flg.CellStyle = True
    Tables("表A").DefaultRowHeight = 50
    Tables("表A").DefaultColWidth = 100
   
    Tables("表A").SaveExcel(dlg.FileName, "表A",flg)  \'保存文件
   
    Dim Book As New XLS.Book(dlg.FileName) \'定义一个Excel工作簿
    Dim Sheet As XLS.Sheet = Book.Sheets("表A") \'引用工作簿的第一个工作表
    Dim Style As XLS.Style
    For r As Integer = 0 To sheet.Rows.count-1
        For c As Integer = 0 To sheet.cols.count-1
            style = sheet(r, c).Style
            If sheet(r, c).Text = "" Then
                sheet(r, c).value = "123"
                style = Book.NewStyle() \'定义新样式
            End If
            Style.BorderTop = XLS.LineStyleEnum.Thin
            Style.BorderBottom = XLS.LineStyleEnum.Thin
            Style.BorderLeft = XLS.LineStyleEnum.Thin
            Style.BorderRight = XLS.LineStyleEnum.Thin
            Style.BorderColorTop = Color.Red
            Style.BorderColorBottom = Color.Red
            Style.BorderColorLeft = Color.Red
            Style.BorderColorRight = Color.Red
            sheet(r, c).Style = style
        Next
    Next
    book.save(dlg.FileName)
End If


--  作者:大红袍
--  发布时间:2016/8/18 17:08:00
--  

 

http://www.foxtable.com/webhelp/scr/2121.htm