代码如下
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这里吗?
建议指定区域处理,不要指定整列。这种自动行高对合并单元格是无效的
那是有点麻烦 这个中间的行数量是根据表行数自动生成的
[此贴子已经被作者于2024/4/10 10:50:44编辑过]
明细行数是不定的,但是从合计开始后面的行数是固定的,取【总行数 - 合计开始后面的行数】,就是前面需要处理的行数了
根据思路 调整了下代码 但是没有效果 能麻烦帮忙看下吗
代码如下:
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编辑过]
试试
……
Dim Rg As MSExcel.Range = Ws.Range("A11:K" & Ws.UsedRange.Rows.Count - 7)Rg.WrapText = True
Rg.EntireRow.AutoFit '自动调整行高
wb.Saved = True
……