Export data to excel

Hi, 

I need to export the data from a file (number, name and address) to an excel file.

I had this done on NetExpress but now I need to "pass" to Visual Cobol WPF.

Does anyone have a small example that can send me how to create the file in excel, export the data to the cells and then save and close the file?

I already ran the forum here but could not find any answer to what I need.

 

Thanks

Alberto Ferraz

Parents
  • The is the .Net Cobol program:

    $set ilusing "Microsoft.Office.Interop.Excel"
    program-id. Write2Excel as "NetCobol2Excel.Write2Excel".

    data division.
    working-storage section.

    01 W-Filename string.

    01 W-ExcelApp type Application.
    01 W-ExcelWorkBook type Workbook.
    01 W-ExcelWorkSheet type Worksheet.

    01 W-Zeile binary-long.

    procedure division.

    DISPLAY 1 UPON ARGUMENT-NUMBER.
    ACCEPT W-Filename FROM ARGUMENT-VALUE.
    if type String::IsNullOrEmpty(W-Filename)
    move "C:\temp\Cobol2Excel.xlsx" to W-Filename
    end-if.

    set W-ExcelApp to new Application
    set W-ExcelWorkBook to W-ExcelApp::Workbooks::Add(1)
    set W-ExcelWorkSheet to W-ExcelWorkBook::Sheets[1] as type Worksheet.

    set W-ExcelWorkSheet::Name to "Test Cobol"
    move 1 to W-Zeile
    set W-ExcelWorkSheet::Cells[W-Zeile, 1] to type DateTime::Now::ToString()
    set W-ExcelWorkSheet::Cells[W-Zeile, 2] to 100
    add 1 to W-Zeile
    set W-ExcelWorkSheet::Cells[W-Zeile, 1] to "Row " & W-Zeile & ", Column A"
    set W-ExcelWorkSheet::Cells[W-Zeile, 2] to 200
    add 1 to W-Zeile
    set W-ExcelWorkSheet::Cells[W-Zeile, 1] to "Row " & W-Zeile & ", Column A"
    set W-ExcelWorkSheet::Cells[W-Zeile, 2] to 300
    add 1 to W-Zeile
    set W-ExcelWorkSheet::Cells[W-Zeile, 1] to W-Filename
    set W-ExcelWorkSheet::Cells[W-Zeile, 2] to "=SUM(B1:B3)"

    * invoke W-ExcelWorkBook::SaveAs(W-Filename) *> fails
    invoke W-ExcelWorkBook::SaveAs(W-Filename,
    type System.Reflection.Missing::Value
    type System.Reflection.Missing::Value
    type System.Reflection.Missing::Value
    type System.Reflection.Missing::Value
    type System.Reflection.Missing::Value
    type XlSaveAsAccessMode::xlNoChange
    type System.Reflection.Missing::Value
    type System.Reflection.Missing::Value
    type System.Reflection.Missing::Value
    type System.Reflection.Missing::Value
    type System.Reflection.Missing::Value
    )

    invoke W-ExcelWorkBook::Close()
    invoke W-ExcelApp::Quit()

    stop run.

    end program Write2Excel.

    If you send a mail address I can send you the VS solution.
    Freundliche Grüsse
    Werner Lanter
Reply
  • The is the .Net Cobol program:

    $set ilusing "Microsoft.Office.Interop.Excel"
    program-id. Write2Excel as "NetCobol2Excel.Write2Excel".

    data division.
    working-storage section.

    01 W-Filename string.

    01 W-ExcelApp type Application.
    01 W-ExcelWorkBook type Workbook.
    01 W-ExcelWorkSheet type Worksheet.

    01 W-Zeile binary-long.

    procedure division.

    DISPLAY 1 UPON ARGUMENT-NUMBER.
    ACCEPT W-Filename FROM ARGUMENT-VALUE.
    if type String::IsNullOrEmpty(W-Filename)
    move "C:\temp\Cobol2Excel.xlsx" to W-Filename
    end-if.

    set W-ExcelApp to new Application
    set W-ExcelWorkBook to W-ExcelApp::Workbooks::Add(1)
    set W-ExcelWorkSheet to W-ExcelWorkBook::Sheets[1] as type Worksheet.

    set W-ExcelWorkSheet::Name to "Test Cobol"
    move 1 to W-Zeile
    set W-ExcelWorkSheet::Cells[W-Zeile, 1] to type DateTime::Now::ToString()
    set W-ExcelWorkSheet::Cells[W-Zeile, 2] to 100
    add 1 to W-Zeile
    set W-ExcelWorkSheet::Cells[W-Zeile, 1] to "Row " & W-Zeile & ", Column A"
    set W-ExcelWorkSheet::Cells[W-Zeile, 2] to 200
    add 1 to W-Zeile
    set W-ExcelWorkSheet::Cells[W-Zeile, 1] to "Row " & W-Zeile & ", Column A"
    set W-ExcelWorkSheet::Cells[W-Zeile, 2] to 300
    add 1 to W-Zeile
    set W-ExcelWorkSheet::Cells[W-Zeile, 1] to W-Filename
    set W-ExcelWorkSheet::Cells[W-Zeile, 2] to "=SUM(B1:B3)"

    * invoke W-ExcelWorkBook::SaveAs(W-Filename) *> fails
    invoke W-ExcelWorkBook::SaveAs(W-Filename,
    type System.Reflection.Missing::Value
    type System.Reflection.Missing::Value
    type System.Reflection.Missing::Value
    type System.Reflection.Missing::Value
    type System.Reflection.Missing::Value
    type XlSaveAsAccessMode::xlNoChange
    type System.Reflection.Missing::Value
    type System.Reflection.Missing::Value
    type System.Reflection.Missing::Value
    type System.Reflection.Missing::Value
    type System.Reflection.Missing::Value
    )

    invoke W-ExcelWorkBook::Close()
    invoke W-ExcelApp::Quit()

    stop run.

    end program Write2Excel.

    If you send a mail address I can send you the VS solution.
    Freundliche Grüsse
    Werner Lanter
Children
No Data