附VB的代码:
Public Sub PublicFpToExcel(ByVal frm As Form, ByVal CommonDialog As CommonDialog, fp As fpSpread)
On Error GoTo f_Error
Dim i As Long
Dim j As Long
Dim str1 As String
Dim x As Boolean
CommonDialog.CancelError = False
CommonDialog.FileName = "" '默認生成的文件名
CommonDialog.DialogTitle = "Save Export File"
CommonDialog.Filter = "1997-2003 Excel (*.xls)|*.xls|2007-2010 Excel (*.xlsx)|*.xlsx"
CommonDialog.DefaultExt = "*.xls"
CommonDialog.ShowSave
frm.MousePointer = 11
If CommonDialog.FileName <> "" Then
With fp
.MaxRows = .MaxRows + .ColHeaderRows
.InsertRows 1, .ColHeaderRows
For i = 1 To .MaxCols
.Col = i
For j = 0 To .ColHeaderRows - 1
.Row = SpreadHeader + j
str1 = .Text
.Row = j + 1
.CellType = CellTypeEdit
.TypeHAlign = TypeHAlignCenter
.TypeVAlign = TypeVAlignCenter
.Text = str1
Next j
Next i
x = .ExportToExcel(CommonDialog.FileName, "Sheet1", App.Path & "\ToExcelLog.TXT")
.DeleteRows 1, .ColHeaderRows
.MaxRows = .MaxRows - .ColHeaderRows
End With
If x Then
MsgBox "输出数据成功", vbInformation + vbOKOnly, "提示"
Else
MsgBox "输出数据失败", vbExclamation + vbOKOnly, "提示"
End If
End If
frm.MousePointer = 0
Exit Sub
f_Error:
frm.MousePointer = 0
MsgBox "错误码:" & Err.Number & Chr(13) & Err.Source & ":" & Err.Description, vbExclamation, "提示"
End Sub
就是调用以上过程,能一并导出,但不用这种方法,能直接导入表头吗,并支持Excel 2007 -2010 |