|
<>用VBA编写如下代码后发现导出excel时如果备注字段“NOTE”内容太多,导致导出的备注字段为空,如果内容不多就正常,是否是格式问题,代码如下,请高手指教!</P>
<>====================================</P>
<>===============================<BR>Private Sub 导出到Excel_Click() </P>
<p>
<P>On Error GoTo Err_OutputToExcel<BR>Dim xlApp As New Excel.Application<BR>Dim xlBook As Excel.Workbook<BR>Dim xlsheet As New Excel.Worksheet<BR>Dim Conn As New ADODB.Connection<BR>Dim Rec As New ADODB.Recordset<BR>Dim strSQL As String<BR>Dim i As Integer, j As Integer, m As Integer, n As Integer<BR> <BR>Set xlApp = CreateObject("Excel.Application")<BR>Set xlBook = xlApp.Workbooks.add<BR>Set xlsheet = xlBook.Worksheets(1)<BR>Set Conn = CurrentProject.Connection </P>
<p>
<P><FONT color=#000000>strSQL = "SELECT * FROM QUOTE_MAIN " <BR>strSQL = strSQL & "Where QUOTE_NO_TIMES =" & Me.QUOTE_NO_TIMES & ";"</FONT> </P>
<p>
<P>Rec.Open strSQL, Conn, adOpenStatic, adLockOptimistic </P>
<p>
<P>i = 1: j = 9<BR> <BR>xlsheet.Name = Me.QUOTE_NO<BR>xlApp.Visible = True '显示 </P>
<p>
<P> With xlsheet<BR> .Columns("a:j").Font.Size = 10<BR> .Columns("a:j").VerticalAlignment = xlVAlignCenter '垂直居中<BR> .Columns("A:J").HorizontalAlignment = xlHAlignLeft '1列水平居中对齐<BR> End With </P>
<p>
<P> With xlsheet<BR> '设置列宽<BR> .Cells(1, 1).ColumnWidth = 13<BR> .Cells(1, 2).ColumnWidth = 20<BR> .Cells(1, 3).ColumnWidth = 6<BR> .Cells(1, 4).ColumnWidth = 7.5<BR> .Cells(1, 5).ColumnWidth = 15<BR> .Cells(1, 6).ColumnWidth = 10<BR> .Cells(1, 7).ColumnWidth = 6<BR> .Cells(1, 8).ColumnWidth = 15<BR> .Cells(1, 9).ColumnWidth = 9<BR> .Cells(1, 10).ColumnWidth = 15<BR> <BR> End With<BR> <BR> '设置表头<BR> xlApp.Range("A1:" & Chr(64 + Rec.Fields.Count) & 1).Select<BR> With xlApp.Selection<BR> .HorizontalAlignment = xlCenter<BR> .VerticalAlignment = xlCenter<BR> .WrapText = False<BR> .Orientation = 0<BR> .AddIndent = False<BR> .IndentLevel = 0<BR> .ShrinkToFit = False<BR> .ReadingOrder = xlContext<BR> .MergeCells = False<BR> End With<BR> xlApp.Selection.Merge<BR> <BR> xlApp.Range("A1:" & Chr(64 + Rec.Fields.Count) & 1).Select<BR> With xlApp.Selection<BR> .HorizontalAlignment = xlCenter<BR> .VerticalAlignment = xlCenter<BR> .WrapText = False<BR> .Orientation = 0<BR> .AddIndent = False<BR> .IndentLevel = 0<BR> .ShrinkToFit = False<BR> .ReadingOrder = xlContext<BR> .MergeCells = False<BR> End With<BR> xlApp.Selection.Merge<BR> <BR> xlApp.Range("A1").Select<BR> xlApp.ActiveCell.FormulaR1C1 = "QUOTE SHEET"<BR> With xlApp.Selection.Font<BR> .Name = "Arial Black"<BR> .Size = 16<BR> .Strikethrough = False<BR> .Superscript = False<BR> .Subscript = False<BR> .OutlineFont = False<BR> .Shadow = False<BR> .Underline = xlUnderlineStyleNone<BR> .ColorIndex = xlAutomatic<BR> End With </P>
<p>
<P> xlApp.Range("A3").Select<BR> xlApp.ActiveCell.FormulaR1C1 = "PRICE NO."<BR> xlApp.Range("B3").Select<BR> xlApp.ActiveCell.FormulaR1C1 = QUOTE_NO<BR> <BR> xlApp.Range("A4").Select<BR> xlApp.ActiveCell.FormulaR1C1 = "PRICE TIMES"<BR> xlApp.Range("B4").Select<BR> xlApp.ActiveCell.FormulaR1C1 = QUOTE_TIMES<BR> <BR> xlApp.Range("A5").Select<BR> xlApp.ActiveCell.FormulaR1C1 = "FOLLOW NO."<BR> xlApp.Range("B5").Select<BR> xlApp.ActiveCell.FormulaR1C1 = SALPME_FOLLOW_NO<BR> <BR> xlApp.Range("A6").Select<BR> xlApp.ActiveCell.FormulaR1C1 = "FACTORY"<BR> xlApp.Range("B6").Select<BR> xlApp.ActiveCell.FormulaR1C1 = FACTORY<BR> <BR> xlApp.Range("A7").Select<BR> xlApp.ActiveCell.FormulaR1C1 = "CUSTOMER"<BR> xlApp.Range("B7").Select<BR> xlApp.ActiveCell.FormulaR1C1 = CUSTOM |
|