Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共6 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:excel打印自动行高问题请教

1楼
allenyen 发表于:2024/4/10 10:21:00
代码如下

Dim djh As String = e.Form.Controls("djh").value
Dim Book As New XLS.Book(ProjectPath & "Attachments\采购订单PDF竖向.xls")
Dim fl As String = ProjectPath & "Reports\采购订单PDF竖向.xls"
Dim fl2 As String = ProjectPath & "Reports\采购订单" & djh & ".pdf"
Book.Build() '生成细节区
Book.Save(fl)

Dim App As New MSExcel.Application
try
    Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(fl)
    Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
    Dim Rg As MSExcel.Range = Ws.Columns("F")
    'Dim Rg As MSExcel.Range = Ws.Range("A11:A20")   '引用连续的单元格区域
    Rg.WrapText = True
    Rg.EntireRow.AutoFit  '自动调整行高
    wb.Saved = True
    wb.ExportAsFixedFormat(MSExcel.XlFixedFormatType.xlTypePDF, fl2, MsExcel.XlFixedFormatQuality.xlQualityStandard, True, False,  System.Reflection.Missing.Value,  System.Reflection.Missing.Value, True,  System.Reflection.Missing.Value)
    app.quit
    catch
    app.quit
End try


excel 模板

图片点击可在新窗口打开查看


现代码生成效果
图片点击可在新窗口打开查看

通过以上代码备注列的自动行高已实现,但是下面条款和注意事项的行高会丢失,变成一小行,无法显示全文字,请教下这个是哪里问题 是WS.RANGE这里吗?

2楼
有点蓝 发表于:2024/4/10 10:35:00
建议指定区域处理,不要指定整列。这种自动行高对合并单元格是无效的
3楼
allenyen 发表于:2024/4/10 10:50:00
那是有点麻烦 这个中间的行数量是根据表行数自动生成的
[此贴子已经被作者于2024/4/10 10:50:44编辑过]
4楼
有点蓝 发表于:2024/4/10 10:58:00
明细行数是不定的,但是从合计开始后面的行数是固定的,取【总行数 - 合计开始后面的行数】,就是前面需要处理的行数了
5楼
allenyen 发表于:2024/4/10 11:24:00
根据思路 调整了下代码 但是没有效果 能麻烦帮忙看下吗

代码如下:
Dim djh As String = e.Form.Controls("djh").value
    Dim Book As New XLS.Book(ProjectPath & "Attachments\采购订单PDF竖向.xls")
    Dim fl As String = ProjectPath & "Reports\采购订单PDF竖向.xls"
    Dim fl2 As String = ProjectPath & "Reports\采购订单" & djh & ".pdf"
    Book.Build() '生成细节区
    Book.Save(fl)
    
    Dim App As New MSExcel.Application
    try
        Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(fl)
        Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
        'Dim Rg As MSExcel.Range = Ws.Columns("F")
        'Dim Rg As MSExcel.Range = Ws.Range("C11:D11,E11:K11")'引用不连续的单元格区域
        Dim Rg As MSExcel.Range
        'MessageBox.Show(Rg.Rows.Count)
        Dim rgs As Integer = Rg.Rows.Count
        rgs = rgs - 7
        'MessageBox.Show(rgs)
        For i As Integer = 0 To rgs
            For j As Integer = 0 To 12
                Rg = Ws.Cells(i,j)
                ''Rg.Value = "abc"
            Next
        Next
        
        Rg.WrapText = True
        Rg.EntireRow.AutoFit  '自动调整行高
        wb.Saved = True
        wb.ExportAsFixedFormat(MSExcel.XlFixedFormatType.xlTypePDF, fl2, MsExcel.XlFixedFormatQuality.xlQualityStandard, True, False,  System.Reflection.Missing.Value,  System.Reflection.Missing.Value, True,  System.Reflection.Missing.Value)
        app.quit
        catch
        app.quit
    End try

[此贴子已经被作者于2024/4/10 11:24:46编辑过]
6楼
有点蓝 发表于:2024/4/10 11:36:00
试试
……
Dim Rg As MSExcel.Range = Ws.Range("A11:K" & Ws.UsedRange.Rows.Count - 7)
Rg.WrapText = True
Rg.EntireRow.AutoFit  '自动调整行高
wb.Saved = True
……
共6 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .06592 s, 2 queries.