以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  帮我看看导出excel  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=82462)

--  作者:冰淇淋小子
--  发布时间:2016/3/18 10:28:00
--  帮我看看导出excel
我现在已经实现了:
Dim Book As New XLS.Book(ProjectPath & "Attachments\\设备一览表.xls")
Dim fl As String = "E:\\Desktop\\设备一览表.xls"
Book.Build() \'生成细节区
Book.Save(fl) \'保存工作簿
Dim Proc As New Process \'打开工作簿
Proc.File = fl
Proc.Start()

如何把使用年限添加到上面,我一添加就报错
    Dim d As Double = dt.Rows(r)("使用年限")
    Sheet(r + 1,dt.Cols("使用年限").Index).value = d \\ 365 & "年" & (d Mod 365) \\ 30 & "月"
   

--  作者:狐狸爸爸
--  发布时间:2016/3/18 10:37:00
--  

错误提示是什么?

 

通常必须在Build之后,定义Sheet,然后设置单元格内容:

 

Dim Book As New XLS.Book(ProjectPath & "Attachments\\设备一览表.xls")
Dim fl As String = "E:\\Desktop\\设备一览表.xls"
Book.Build() \'生成细节区
Book.Save(fl) \'保存工作簿

Dim Sheet As XLS.Sheet = Book.Sheets(0)
Sheet(10,10).value = “内容”
Dim Proc As New Process \'打开工作簿
Proc.File = fl
Proc.Start()

 


 


--  作者:Hyphen
--  发布时间:2016/3/18 10:38:00
--  
报什么错误?

定位一下运行到什么地方http://www.foxtable.com/help/topics/1485.htm

--  作者:冰淇淋小子
--  发布时间:2016/3/18 11:14:00
--  
Dim dt As Table = Tables("南京徳亨文生物科技有限公司设备一览表")
Dim flg As New SaveExcelFlags
flg.RowNumber = True
flg.CellStyle = True
dt.SaveExcel("E:\\Desktop\\南京徳亨文生物科技有限公司设备一览表.xls",)
Dim Book As New XLS.Book(ProjectPath & "Attachments\\南京徳亨文生物科技有限公司设备一览表.xls","abc",flg)
Dim Sheet As XLS.Sheet = Book.Sheets("abc") \'引用工作簿的第一个工作表

Dim Style As Xls.Style
style = Book.NewStyle \'新建一个样式
Style.ForeColor = Color.Red
style.FontBold = True \'样式的背景颜色设为红色
Dim Style1 As Xls.Style
style1 = Book.NewStyle \'新建一个样式
Style1.BackColor = Color.yellow
style1.BorderBottom = XLS.LineStyleEnum.Thin
style1.Bordertop = XLS.LineStyleEnum.Thin
style1.Borderleft = XLS.LineStyleEnum.Thin
style1.Borderright = XLS.LineStyleEnum.Thin

style1.FontBold = True \'样式的背景颜色设为红色

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
    
    
    If dt.Rows(r)("中心") = "公共设施" OrElse dt.Rows(r)("中心") = "离职" Then
        For c As Integer = 0 To dt.Cols.Count -1
            Sheet(r +1, c).style = style1
        Next
    End If
    If dt.rows(r)("内存") =  "2G"  Then \'如果折扣大于等于0.15
        Sheet(r + 1,dt.Cols("内存").Index).Style = Style \'设置折扣单元格的样式
    End If
    If dt.Rows(r)("生产日期").year = 2008 OrElse dt.Rows(r)("生产日期").year = 2008 OrElse dt.Rows(r)("生产日期").year = 2008 Then
        Sheet(r + 1,dt.Cols("生产日期").Index).Style = Style \'设置折扣单元格的样式
    End If
    If dt.Rows(r)("使用年限") / 365 >= 5 Then
        Sheet(r + 1,dt.Cols("使用年限").Index).Style = Style \'设置折扣单元格的样式
    End If
    Dim d As Double = dt.Rows(r)("使用年限")
    Sheet(r + 1,dt.Cols("使用年限").Index).value = d \\ 365 & "年" & (d Mod 365) \\ 30 & "月"
    
Next

book.Save("E:\\Desktop\\南京徳亨文生物科技有限公司设备一览表.xls")
Dim proc As new Process
proc.File = "E:\\Desktop\\南京徳亨文生物科技有限公司设备一览表.xls"
proc.Start




 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:南京徳亨文生物科技有限公司设备一览表.rar

我要实现我压缩包的格式,到底怎么设置,我调试了一周了,还是报错,还不是我想要的格式


--  作者:冰淇淋小子
--  发布时间:2016/3/18 11:15:00
--  

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

现在报这个错误

--  作者:Hyphen
--  发布时间:2016/3/18 11:29:00
--  
代码走神,串道了
dt.SaveExcel("E:\\Desktop\\南京徳亨文生物科技有限公司设备一览表.xls","abc",flg)
Dim Book As New XLS.Book(ProjectPath & "Attachments\\南京徳亨文生物科技有限公司设备一览表.xls")

--  作者:冰淇淋小子
--  发布时间:2016/3/18 11:43:00
--  

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

导出还是不对。

--  作者:冰淇淋小子
--  发布时间:2016/3/18 11:44:00
--  
顶部标题和字段没有了
--  作者:冰淇淋小子
--  发布时间:2016/3/18 11:58:00
--  
 添加列标题应该是模板里面现在的标题,只要填入数据就可以了。这个怎么设置
--  作者:大红袍
--  发布时间:2016/3/21 2:13:00
--  

1、学习excel模板

 

2、要不就直接用vba导出 http://www.foxtable.com/help/topics/2121.htm