0

I am not beeing able to settup a region of cells using Excel OleAutomation, even changing the string type it raises an exception:

    Variant xlApp, wBook, wSheet, vRange, vCell1, vCell2;

    WideString xlFile  = "C:\\Temp\\ExcelTestFile.xlsx",
           xlTitle = "Relatório de Geração";
    try{
         xlApp = CreateOleObject("Excel.Application");
         // Hide Excel
         xlApp.OlePropertySet("Visible", false);
         // Add new Workbook
         xlApp.OlePropertyGet("WorkBooks").OleFunction("Add", -4167);
         // Get WorkBook
         wBook = xlApp.OlePropertyGet("Workbooks").OlePropertyGet("Item", 1);

         // Get WorkSheet
         wSheet = wBook.OlePropertyGet("Worksheets").OlePropertyGet("Item", 1);
         wSheet.OlePropertySet("Name", xlTitle); 
    
         // Set number format
         vCell1 = wSheet.OlePropertyGet("Cells", 3, 4);
         vCell2 = wSheet.OlePropertyGet("Cells", maxRowsInXL + 1, 20);
         vRange = wSheet.OlePropertyGet("Range", vCell1, vCell2);
         //vRange.OlePropertySet("NumberFormat" , "#.###.##0,00" ); // Raise Incorrect Type
         vRange.OlePropertySet("NumberFormat" , L"#.###.##0,00" ); // Raise Can't set region NumberFormat
    }
    catch(Exception &E){
        ShowMessage( E.Message );
        xlApp.OlePropertySet("DisplayAlerts",false);
        xlApp.OleProcedure("Quit");
    }

How can I set up the NumberFormat of a region of cells using Excel Ole Automation?

Thank you very much.

1 Answers1

0

Just use the WideString type:

vRange.OlePropertySet("NumberFormat" , WideString("#.###.##0,00") );