从Visual Basic 6将数据传输到新的Excel工作表

时间:2015-07-08 18:38:44

标签: excel vb6 worksheet

大家好日子!

我需要一些帮助,如何将数据从VB6传输到新的Excel工作表,例如,我希望能够选择以前创建的Excel文件,添加新工作表并将数据保存到其中。< / p>

以下是我目前对项目的看法:

public unsafe override int GetHashCode() 
{
    double d = m_value;
    if (d == 0) {
        // Ensure that 0 and -0 have the same hash code
        return 0;
    }
    long value = *(long*)(&d);
    return unchecked((int)value) ^ ((int)(value >> 32));
}

此子参数仅将表单中的数据导出到新工作簿。

这是出口程序:

Public Sub ExptExcel()

Dim ADAExcelExpt As String
Dim conn As New ADODB.Connection
Dim RS As ADODB.Recordset

With CommonDialog1
 .CancelError = True
 .InitDir = "c:"
 .DialogTitle = "Save Excel File"
 .Filter = "Excel files (*.xls)|*.xls|Excel Files (*.xlsx)|*.xslx"
 .Flags = cdlOFNExplorer Or cdlOFNHideReadOnly Or cdlOFNLongNames
  On Error Resume Next 'trap the cancel error
 .ShowOpen
End With

 If Err = cdlCancel Then 'user cancelled
'Exit Sub or msgbox "User cancelled."
    Exit Sub
'or whatever
 End If


 'exit if no file selected
 If CommonDialog1.FileName = "" Then
    Exit Sub
 End If

  ADAExcelExpt = "E:\Remittance Report\PrintSource.mdb"
  conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ADAExcelExpt & ";"
  conn.CursorLocation = adUseClient

  Set RS = conn.Execute("Select FAGYDES, DedCode, FSERIAL, RANK, FULLNAME, DedAmt, FDEDDESC, FFULDESC, Datefm from tblPrintDeduct")

  'Create a new workbook in Excel
  Dim oExcel As Object
  Dim oBook As Object
  Dim oSheet As Object
  Set oExcel = CreateObject("Excel.Application")
  Set oBook = oExcel.Workbooks.Add
  Set oSheet = oBook.Worksheets(1)

  'Add headers to the worksheet on row 1
  oSheet.Range("A1:I1").Value = Array("AGENCY", "DEDCODE", "AFPSN", "RANK", "FULLNAME", "AMOUNT", "DEDTYPE", "DESCRIPTION", "DATE")
  'Transfer the data to Excel

  oSheet.Range("A2").CopyFromRecordset RS

  oBook.SaveAs (CommonDialog1.FileName)
  oExcel.Quit
  MsgBox ("File Exported!")

  'Close the connection
  RS.Close
  conn.Close

 End Sub

此致

阿隆

0 个答案:

没有答案