以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  关于导出Excel表问题  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=146847)

--  作者:裴保民
--  发布时间:2020/3/4 9:17:00
--  关于导出Excel表问题

Dim b As New XLS.Book
Dim
t As Table = Tables("统计表")
Dim
s As XLS.Sheet = b.Sheets(0)
Dim Chart As WinForm.Chart = Forms("窗口1").Controls("Chart1")
For
c As Integer = 0 To t.Cols.Count -1 \'添加列标题
    s(0, c).Value = t.Cols(c).Name

Next
For
r As Integer = 0 To t.Rows.Count - 1 \'填入数据
   
For c As Integer = 0 To t.Cols.Count -1
        s(r +1, c).Value = t.rows(r)(c)

    Next
Next

\'插入图表

s(t.rows.Count + 2,1).Value = New XLS.Picture(Chart.Image,0,0,422,258)
b.Save("c:\\reports\\test.xls")

Dim
Proc As New Process
Proc.File =
"c:\\reports\\test.xls"
Proc.Start()


看了帮助文件以上只是保存到固定路径上,如果声明一个 SaveFileDialog 用于指定路径和文件名,怎么改一下呀?怎么只保存了文件没有图插到表呢?

[此贴子已经被作者于2020/3/4 9:24:31编辑过]

--  作者:有点蓝
--  发布时间:2020/3/4 9:24:00
--  
http://www.foxtable.com/webhelp/topics/1148.htm
--  作者:裴保民
--  发布时间:2020/3/4 9:26:00
--  
怎么改一下呀?怎么只保存了文件没有图插到表呢?
--  作者:有点蓝
--  发布时间:2020/3/4 9:36:00
--  
贴出代码说明
--  作者:裴保民
--  发布时间:2020/3/4 9:49:00
--  
Dim b As New XLS.Book
Dim t As Table = Tables("收入统计图表窗体_tjTable")
Dim s As XLS.Sheet = b.Sheets(0)
Dim Chart As WinForm.Chart = Forms("收入统计图表窗体").Controls("Chart1")
For c As Integer = 0 To t.Cols.Count -1 \'添加列标题
    s(0, c).Value = t.Cols(c).Name
Next
For r As Integer = 0 To t.Rows.Count - 1 \'填入数据
    For c As Integer = 0 To t.Cols.Count -1
        s(r +1, c).Value = t.rows(r)(c)
    Next
Next
\'插入图表
\'s(t.rows.Count + 2,1).Value = New XLS.Picture(Chart.Image,0,0,422,258)
\'b.Save("c:\\reports\\test.xls")
\'Dim Proc As New Process
\'Proc.File = "c:\\reports\\test.xls"
\'Proc.Start()
Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog 
dlg.Filter= "文本文件|*.xls" \'设置筛选器
dlg.FileName="收入总汇"
If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮
s(t.rows.Count + 2,1).Value = New XLS.Picture(Chart.Image,0,0,422,258)
t.SaveExcel(dlg.FileName, "收入总汇")
End If


--  作者:有点蓝
--  发布时间:2020/3/4 9:52:00
--  
\'插入图表
s(t.rows.Count + 2,1).Value = New XLS.Picture(Chart.Image,0,0,422,258)
Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog 
dlg.Filter= "文本文件|*.xls" \'设置筛选器
dlg.FileName="收入总汇"
If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮
b.Save(dlg.FileName)
End If