以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  导出数据  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=108101)

--  作者:cd_tdh
--  发布时间:2017/10/16 13:07:00
--  导出数据

老师,我设置了一个导出数据按钮,另外设置了一个复选框,用来选择需要导出的列,怎么实现导出的数据就是我选择的列的数据(列宽可以不控制,直接用原来列宽),另外我导出后行高和边框线也没有。

上传了示例麻烦老师看看。

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目1.table

[此贴子已经被作者于2017/10/16 13:10:19编辑过]

--  作者:有点甜
--  发布时间:2017/10/16 14:53:00
--  

 Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" \'设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then
    Dim dt As Table = Tables("表A")
    Dim nms() As String =  "第一列,第二列,第三列,第四列,第五列".split(",")
    Dim Book As New XLS.Book \'定义一个Excel工作簿
    Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表
    Dim st As XLS.Style = Book.NewStyle \'日期列的显示格式
    st.Format = "yyyy-MM-dd"
    st.BorderTop = XLS.LineStyleEnum.Thin
    st.BorderBottom = XLS.LineStyleEnum.Thin
    st.BorderLeft = XLS.LineStyleEnum.Thin
    st.BorderRight = XLS.LineStyleEnum.Thin
    st.BorderColorTop = Color.Red
    st.BorderColorBottom = Color.Red
    st.BorderColorLeft = Color.Red
    st.BorderColorRight = Color.Red
   
   
    Dim style As XLS.Style = Book.NewStyle \'日期列的显示格式
    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
    For c As Integer = 0 To nms.length -1
        Dim dc As Col = dt.Cols(c)
        Sheet(0, c).Value = dc.Caption \'指定列标题
        Sheet.Cols(c).Width = dc.Width \'指定列宽
        sheet(0,c).style = style
    Next
    For r As Integer = 0 To dt.Rows.Count - 1 \'填入数据
        For c As Integer = 0 To nms.length -1
            If dt.Cols(nms(c)).IsDate Then \'如果是日期列
                Sheet(r+1,c).Style = st \'设置显示格式
            Else
                Sheet(r+1,c).Style = style
            End If
            Sheet(r +1, c).Value = dt.rows(r)(nms(c))
        Next
    Next
   
    Book.Save(dlg.FileName)
    Dim Proc As New Process
    Proc.File = dlg.FileName
    Proc.Start()
End If

[此贴子已经被作者于2017/10/16 14:53:30编辑过]

--  作者:cd_tdh
--  发布时间:2017/10/16 16:17:00
--  

老师,这样出来是根据字体大小来调整行高的,怎么用原来数据表里面的行高和字体大小?还有就是复选框选项怎么循环列自动生成选项(比如选项为表A的所有列),导出数据是根据选择的列来导出的。

我直接用系统的导出,截图一,字体大小、行高都原来大小,只是不能动态选择要导出的列。

 


图片点击可在新窗口打开查看此主题相关图片如下:111.jpg
图片点击可在新窗口打开查看
[此贴子已经被作者于2017/10/16 16:25:41编辑过]

--  作者:cd_tdh
--  发布时间:2017/10/16 16:31:00
--  

可能我阐述不清楚,我希望直接导出,或是直接用系统的导出命令Syscmd.Project.ExportToExcel(),在其中增加一个自定义需要导出列的复选组合框来选择需要导出的列。

[此贴子已经被作者于2017/10/16 16:42:20编辑过]

--  作者:有点蓝
--  发布时间:2017/10/16 21:11:00
--  
Dim ccb As WinForm.CheckedComboBox = e.Form.Controls("CheckedComboBox1")
If ccb.Text > "" Then
    Dim lst As new List(of String)
    lst.AddRange(ccb.Text.Split(","))
    For Each c As Col In Tables("表A").Cols
         c.Visible = lst.Contains(c.Name)
    Next
End If
Dim flg As New  SaveExcelFlags
flg.RowNumber = True
flg.CellStyle = True
flg.VisibleOnly = True
Tables("表A").SaveExcel("f:\\123.xls","表A",flg)

Dim Proc As New Process
Proc.File = "f:\\123.xls"
Proc.Start()

--  作者:cd_tdh
--  发布时间:2017/10/17 9:26:00
--  
老师:CheckedComboBox1的enter代码怎么写?
--  作者:有点甜
--  发布时间:2017/10/17 9:32:00
--  
e.sender.Items.Clear
For Each c As Col In Tables("表A").Cols
    e.sender.Items.add(c.name)
Next

--  作者:cd_tdh
--  发布时间:2017/10/17 9:53:00
--  
老师,有点蓝老师的那种方式,直接把表里面的列隐藏了在导出的,导出后,数据表里需要取消隐藏,其他列才显示,还有没其他方式呢?
--  作者:有点甜
--  发布时间:2017/10/17 9:56:00
--  

Dim ccb As WinForm.CheckedComboBox = e.Form.Controls("CheckedComboBox1")
Dim ws As String =  Tables("表A").getColVisibleWidth
If ccb.Text > "" Then
    Dim lst As new List(of String)
    lst.AddRange(ccb.Text.Split(","))
    For Each c As Col In Tables("表A").Cols
        c.Visible = lst.Contains(c.Name)
    Next
End If
Dim flg As New  SaveExcelFlags
flg.RowNumber = True
flg.CellStyle = True
flg.VisibleOnly = True
Tables("表A").SaveExcel("f:\\123.xls","表A",flg)

Tables("表A").SetColVisibleWidth(ws)
Dim Proc As New Process
Proc.File = "f:\\123.xls"
Proc.Start()

[此贴子已经被作者于2017/10/17 10:15:30编辑过]

--  作者:cd_tdh
--  发布时间:2017/10/17 10:03:00
--  
以下是引用有点甜在2017/10/17 9:56:00的发言:

Dim ccb As WinForm.CheckedComboBox = e.Form.Controls("CheckedComboBox1")
Dim ws As String =  Tables("表A").getColVisibleWidth
If ccb.Text > "" Then
    Dim lst As new List(of String)
    lst.AddRange(ccb.Text.Split(","))
    For Each c As Col In Tables("表A").Cols
        c.Visible = lst.Contains(c.Name)
    Next
End If
Dim flg As New  SaveExcelFlags
flg.RowNumber = True
flg.CellStyle = True
flg.VisibleOnly = True
Tables("表A").SaveExcel("f:\\123.xls","表A",flg)

Tables("表A").SetColVisibleWidth(ws)
Dim Proc As New Process
Proc.File = "f:\\123.xls"
Proc.Start()


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