以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=126620)

--  作者:xybcxh
--  发布时间:2018/10/25 13:41:00
--  [求助]
老师好,导出的Excel表怎样自动换行。在论坛上看了好多例子,就是搞不定;还有第一行的例名具中,请老师帮忙。
Dim dt As Table = Tables("设备送修")
Dim nms() As String = {"送修日期","原编号","器具名称","型号规格","故障原因","维修单位","备注"} \'要导出的列名
Dim caps() As String = {"送修日期","原编号","器具名称","型号规格","故障原因","维修单位","备注"} \'对应的列标题
Dim szs() As Integer = {86,110,120,140,250,100,100} \'对应的列宽
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"
For c As Integer = 0 To nms.length -1
    Sheet(0, c).Value = caps(c) \'指定列标题
    Sheet.Cols(c).Width = szs(c) \'指定列宽
    If dt.Cols(nms(c)).IsDate Then \'如果是日期列
        Sheet.Cols(c).Style = st \'设置显示格式
    End If
Next
For r As Integer = 0 To dt.Rows.Count - 1 \'填入数据
    For c As Integer = 0 To nms.length -1
        Sheet(r +1, c).Value = dt.rows(r)(nms(c))
    Next
Next

St.AlignHorz = XLS.AlignHorzEnum.Center \'水平居中

st.WordWrap = True \'自动换行
Book.Save("d:\\杭康设备(修检校)\\送修\\" & dt.rows(0)(nms(0)) & " 送修设备.xls")


Dim Proc As New Process
Proc.File = "d:\\杭康设备(修检校)\\送修\\" & dt.rows(0)(nms(0)) & " 送修设备.xls"
Proc.Start()


--  作者:有点蓝
--  发布时间:2018/10/25 14:05:00
--  
Dim dt As Table = Tables("设备送修")
Dim nms() As String = {"送修日期","原编号","器具名称","型号规格","故障原因","维修单位","备注"} \'要导出的列名
Dim caps() As String = {"送修日期","原编号","器具名称","型号规格","故障原因","维修单位","备注"} \'对应的列标题
Dim szs() As Integer = {86,110,120,140,250,100,100} \'对应的列宽
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.WordWrap = True \'自动换行

Dim st2 As XLS.Style = Book.NewStyle \'日期列的显示格式
st2.WordWrap = True \'自动换行
St.AlignHorz = XLS.AlignHorzEnum.Center \'水平居中

For c As Integer = 0 To nms.length -1
    Sheet(0, c).Value = caps(c) \'指定列标题
    Sheet.Cols(c).Width = szs(c) \'指定列宽
    If dt.Cols(nms(c)).IsDate Then \'如果是日期列
        Sheet.Cols(c).Style = st \'设置显示格式
    Else
        Sheet.Cols(c).Style = st2 \'设置显示格式
    End If
Next
For r As Integer = 0 To dt.Rows.Count - 1 \'填入数据
    For c As Integer = 0 To nms.length -1
        Sheet(r +1, c).Value = dt.rows(r)(nms(c))
    Next
Next

St.AlignHorz = XLS.AlignHorzEnum.Center \'水平居中
st.WordWrap = True \'自动换行
Book.Save("d:\\杭康设备(修检校)\\送修\\" & dt.rows(0)(nms(0)) & " 送修设备.xls")

--  作者:xybcxh
--  发布时间:2018/10/25 14:43:00
--  
老师,已试过,还有第一列不能居中(0列),水平、垂直都一样。

Dim st2 As XLS.Style = Book.NewStyle \'列的显示格式
st2.WordWrap = True \'自动换行
st2.AlignHorz = XLS.AlignHorzEnum.Center \'水平居中
st2.AlignVert = XLS.AlignVertEnum.Center \'垂直居中

--  作者:xybcxh
--  发布时间:2018/10/25 14:59:00
--  
好了
st.Format = "yyyy-MM-dd"


Dim st2 As XLS.Style = Book.NewStyle \'列的显示格式
st2.WordWrap = True \'自动换行
st2.AlignHorz = XLS.AlignHorzEnum.Center \'水平居中
st2.AlignVert = XLS.AlignVertEnum.Center \'垂直居中

For c As Integer = 0 To nms.length -1
    Sheet(0, c).Value = caps(c) \'指定列标题
    Sheet.Cols(c).Width = szs(c) \'指定列宽
    If dt.Cols(nms(c)).IsDate Then \'如果是日期列
        Sheet.Cols(c).Style = st \'设置显示格式
    Else
        Sheet.Cols(c).Style = st2 \'设置显示格式
    End If
Next
For r As Integer = 0 To dt.Rows.Count - 1 \'填入数据
    For c As Integer = 0 To nms.length -1
        Sheet(r +1, c).Value = dt.rows(r)(nms(c))
    Next
Next
st.WordWrap = True \'自动换行
st.AlignHorz = XLS.AlignHorzEnum.Center \'水平居中
st.AlignVert = XLS.AlignVertEnum.Center \'垂直居中
Book.Save("d:\\杭康设备(修检校)\\送修\\" & dt.rows(0)(nms(0))

再加了一次,就可以了,谢谢有点蓝老师。