Foxtable(狐表)用户栏目专家坐堂 → 01.窗口Table中的数据如何输出到Excel报表中


  共有11616人关注过本帖树形打印复制链接

主题:01.窗口Table中的数据如何输出到Excel报表中

美女呀,离线,留言给我吧!
yangming
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:超级版主 帖子:4109 积分:23338 威望:0 精华:21 注册:2008/9/1 20:07:00
  发帖心情 Post By:2011/12/18 19:31:00 [显示全部帖子]

Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
    MessageBox.Show("你要保存为:" & dlg.FileName,"提示") '提示用户选择的文件
End If
Dim dt As Table = Tables("窗口1_Table1")
Dim Book As New XLS.Book '定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
For c As Integer = 0 To dt.Cols.Count -1 '添加列标题
    Sheet(0, c).Value = dt.Cols(c).Name
Next
For r As Integer = 0 To dt.Rows.Count - 1 '填入数据
    For c As Integer = 0 To dt.Cols.Count -1
        Sheet(r +1, c).Value = dt.rows(r)(c)
    Next
    Next
Book.Save(dlg.FileName)
Dim Result As DialogResult
Result = MessageBox.Show("已保存,需要打开文件吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Result = DialogResult.Yes Then
    Dim Proc As New Process
Proc.File = dlg.FileName
Proc.Start()
Else
    End If

 回到顶部
美女呀,离线,留言给我吧!
yangming
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:超级版主 帖子:4109 积分:23338 威望:0 精华:21 注册:2008/9/1 20:07:00
  发帖心情 Post By:2011/12/18 19:39:00 [显示全部帖子]

也可以直接打印窗口表中的数据,比如,我做过的一个工资表中的按钮,当查询后,打印查询结果的一个专业报表的代码:

Dim s As String
If e.Form.Controls("Label6").text = "当月工资表" Then
    s = Tables("主表")(0,0) & Format(Date.Today,"yyyy年MM月") & "工资表"
Else
    s = e.Form.Controls("Label6").text
End If
Dim doc As New PrintDoc '定义一个新报表
Dim rt As New prt.RenderTable '定义一个新表格
Dim rx As New prt.RenderText()
Dim tb As Table = Tables("工资_Table1")
Dim ColNames As New List(Of String)
rx.Text= Chr(13) & Chr(10) & s & Chr(13) & Chr(10) & Chr(13) & Chr(10)
rx.Style.TextAlignHorz=prt.AlignHorzEnum.Center
rx.Style.TextAlignVert = prt.AlignVertEnum.Top
rx.Style.FontSize =14
rx.Style.FontBold = True '字体加粗
rx.Style.F
Doc.Body.Children.Add(rx)
For Each cl As Col In tb.Cols '排除隐藏列
    If cl.Visible Then
        ColNames.Add(cl.Name)
    End If
Next
rt.Style.Font = tb.Font
For c As Integer = 0 To ColNames.Count - 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 Then '如果是数值列
        rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
    Else
        rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Center
    End If
    For r As Integer = 0 To tb.Rows.Count -1 '开始填入该列内容
        rt.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c))
    Next
Next
Dim cnt As Integer = rt.Rows.Count
rt.Cells(cnt,1).Text = "总计"
For c As Integer = 0 To ColNames.Count - 1 '逐列设置和填入内容
    If tb.Cols(ColNames(c)).IsNumeric And ColNames(c)<> "工号" Then
        rt.Cells(cnt,c).Text = tb.Compute("Sum(" & ColNames(c) & ")")
    End If
Next

rt.rows(0).Height= 8
rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) '灰色网格线
rt.CellStyle.Spacing.All = 0.5 '单元格内距设为0.5毫米
rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All '利用行组,将第一行设为表头.
rt.Style.TextAlignVert = prt.AlignVertEnum.Center '垂直居中
doc.PageSetting.Landscape = True '横向打印
Doc.PageSetting.LeftMargin = 15 '设置左边距
Doc.PageSetting.RightMargin = 15 '设置右边距
Doc.Body.Children.Add(rt) '将表格加入到报表
doc.Preview()


 回到顶部