以文本方式查看主题

-  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=74350)

--  作者:ljh29206
--  发布时间:2015/9/9 11:24:00
--  合并导出数据到excel格式设置求助

如题 用以下这种方式导出数据

 

    Dim dt As Table = Tables("空滤制品明细表")
    dt.Filter =  flt2
    Dim Book As New XLS.Book \'定义一个Excel工作簿
    If dt.Rows.Count > 0 Then
        Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表
        sheet.name ="库存表"
        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
    End If

    Book.Save( dpth & "导出数据.xls")

在保存数据的时候

 

1如何 设置导出数据 的日期列 为  datelongtime 格式  ,

 

2如何使到 导出的数据  的列宽 为最合适状态 (像EXCEL里面双击列 ,自动拉伸到最合适位置)


--  作者:大红袍
--  发布时间:2015/9/9 11:29:00
--  

设置单元格格式。

 

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

 

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

 

要设置自动行高或列宽

 

Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("D:\\Report.xls")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim Rg As MSExcel.Range = Ws.Cells
\'Rg.EntireColumn.AutoFit   \'自动调整列宽

Rg.WrapText = True
Rg.EntireRow.AutoFit  \'自动调整行高
App.Visible = True


--  作者:大红袍
--  发布时间:2015/9/9 11:41:00
--  

Dim dt As Table = Tables("表A")
If dt.Rows.Count > 0 Then
    Dim App As New MSExcel.Application
    Dim Wb As MSExcel.WorkBook = App.WorkBooks.Add
    Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
    App.DisplayAlerts = False
    ws.name ="库存表"
    For c As Integer = 0 To dt.Cols.Count -1 \'添加列标题
        ws.Cells(1, c+1).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
            If dt.cols(c).IsDate Then
                ws.cells(r+2, c+1).NumberFormat = "yyyy-m-d h:mm:ss"
            End If
            ws.cells(r+2, c+1).Value = dt.rows(r)(c)
        Next
    Next
    Dim Rg As MSExcel.Range = Ws.Cells
    Rg.EntireColumn.AutoFit   \'自动调整列宽
   
    \'Rg.WrapText = True
    \'Rg.EntireRow.AutoFit  \'自动调整行高
    wb.Saveas("d:\\导出数据.xls")
    \'app.visible = True
End If