以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  保存为EXCEL如何实现动态路径?谢谢  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=17024)

--  作者:雨中的泪
--  发布时间:2012/3/1 12:07:00
--  保存为EXCEL如何实现动态路径?谢谢
 

Dim dt As Table = Tables("项目")

Dim Book As New XLS.Book \'定义一个Excel工作簿

Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表

Dim Style As Xls.Style = Book.NewStyle \'新建一个样式

Style.AlignHorz = XLS.AlignHorzEnum.Center

Style.AlignVert = XLS.AlignVertEnum.Center

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(0,1).Value = "公示表"

Dim Style1 As XLS.Style = Book.NewStyle
Style1.FontBold = True
Sheet(0,1).Style = Style1

For c As Integer = 0 To dt.Cols.Count -1 \'添加列标题

Sheet(1, c).Value = dt.Cols(c).Name

Sheet(1,c).Style = Style

Next

For r As Integer = 0 To dt.Rows.Count - 1 \'填入数据

    For c As Integer = 0 To dt.Cols.Count -1

        Sheet(r +2, c).Value = dt.rows(r)(c)

Sheet(r+2,c).Style = Style

    Next

   Next

\'打开工作簿

Book.Save("c:\\项目.xls")

Dim Proc As New Process

Proc.File = "c:\\项目.xls"

Proc.Start()


--  作者:雨中的泪
--  发布时间:2012/3/1 12:08:00
--  

Book.Save("c:\\项目.xls")

想在这句前打开一个窗口,然后由用户选择保存路径

 

下面的就打开刚才用户保存的excel文件

Dim Proc As New Process

Proc.File = "c:\\项目.xls"

Proc.Start()

 


--  作者:狐狸爸爸
--  发布时间:2012/3/1 12:29:00
--  

http://www.foxtable.com/help/topics/0329.htm

 


--  作者:雨中的泪
--  发布时间:2012/3/1 12:54:00
--  
 

Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" \'设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮
    MessageBox.Show("你要保存为:" & dlg.FileName,"提示") \'提示用户选择的文件

Book.Save("c:\\项目.xls")


End If


Book.Save("c:\\项目.xls")

Dim Proc As New Process

Proc.File = "c:\\项目.xls"

Proc.Start()


--  作者:雨中的泪
--  发布时间:2012/3/1 12:55:00
--  

动态的路径如何获得?

谢谢


--  作者:雨中的泪
--  发布时间:2012/3/1 13:23:00
--  

Book.Save("c:\\项目.xls")

Proc.File = "c:\\项目.xls"

 

如何获得SaveFileDialog 中用户选择的路径?

谢谢


--  作者:雨中的泪
--  发布时间:2012/3/1 13:47:00
--  
老大帮帮忙
--  作者:雨中的泪
--  发布时间:2012/3/1 14:29:00
--  
老大帮帮忙

--  作者:雨中的泪
--  发布时间:2012/3/1 14:36:00
--  
 

Dim dt As Table = Tables("项目")

Dim Book As New XLS.Book \'定义一个Excel工作簿

Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表

Dim Style As Xls.Style = Book.NewStyle \'新建一个样式

Style.AlignHorz = XLS.AlignHorzEnum.Center

Style.AlignVert = XLS.AlignVertEnum.Center

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(0,1).Value = "公示表"

Dim Style1 As XLS.Style = Book.NewStyle
Style1.FontBold = True
Sheet(0,1).Style = Style1

For c As Integer = 0 To dt.Cols.Count -1 \'添加列标题

Sheet(1, c).Value = dt.Cols(c).Name

Sheet(1,c).Style = Style

Next

For r As Integer = 0 To dt.Rows.Count - 1 \'填入数据

    For c As Integer = 0 To dt.Cols.Count -1

        Sheet(r +2, c).Value = dt.rows(r)(c)

Sheet(r+2,c).Style = Style

    Next

   Next

\'打开工作簿

Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" \'设置筛选器

dlg. title= "生成上报文件"       \'设置对话框标题
dlg.OverwritePrompt = True  \'对于已经存在的文件名,是否出现覆盖警告
If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮
    MessageBox.Show("你要保存为:" & dlg.FileName,"提示") \'提示用户选择的文件

If FileSys.FileExists(dlg.filename) Then    \'如果指定的文件存在
    FileSys.DeleteFile(dlg.filename,2,2)     \'则彻底删除之
    End If

Book.Save("dlg.FileName")

Dim Proc As New Process

Proc.File = " dlg.FileName"

Proc.Start()


End If


--  作者:雨中的泪
--  发布时间:2012/3/1 14:36:00
--  
这样不对呀