I’m using a custom package named DataExportUtils to generate Excel files from queries in PL/SQL. Though the file is created, I encounter an error when opening it with Excel:
Error occurred in the given section during file load: Style
I suspect the issue lies with this header setup:
-- Configure headers
owa_util.mime_header('application/vnd.ms-excel', FALSE);
I attempted to add an XML declaration:
<?xml version="1.0" encoding="UTF-8"?>
However, this altered the error to: Error occurred in the given section during file load: 'Strict Parse Error'
Here’s the complete code for my procedure:
/* To execute, use */
execute departmentreport;
CREATE OR REPLACE PROCEDURE departmentReport AS
v_query_wages VARCHAR2(200) := 'SELECT surname,given_name,wage FROM hr.staff ORDER BY surname,given_name';
v_query_details VARCHAR2(200) := 'SELECT surname,given_name,phone,email_addr FROM hr.staff ORDER BY surname,given_name';
v_query_startdate VARCHAR2(200) := 'SELECT surname,given_name,to_char(start_date,''MM/DD/YYYY'') start_date FROM hr.staff ORDER BY surname,given_name';
reportDocument ExcelDocumentType := ExcelDocumentType();
v_sheet_record DataExportUtils.T_WORKSHEET_DATA := NULL;
v_sheet_collection DataExportUtils.WORKSHEET_TABLE := DataExportUtils.WORKSHEET_TABLE();
fileContent ExcelDocumentLine := ExcelDocumentLine();
v_output_file UTL_FILE.FILE_TYPE;
BEGIN
-- Wages sheet
v_sheet_record.query := v_query_wages;
v_sheet_record.worksheet_name := 'Staff_Wages';
v_sheet_record.col_count := 3;
v_sheet_record.col_width_list := '30,25,18';
v_sheet_record.col_header_list := 'Surname,Given_Name,Wage';
v_sheet_collection.EXTEND;
v_sheet_collection(v_sheet_collection.count) := v_sheet_record;
-- Details sheet
v_sheet_record.query := v_query_details;
v_sheet_record.worksheet_name := 'Staff_Details';
v_sheet_record.col_count := 4;
v_sheet_record.col_width_list := '30,25,22,28';
v_sheet_record.col_header_list := 'Surname,Given_Name,Phone,Email';
v_sheet_collection.EXTEND;
v_sheet_collection(v_sheet_collection.count) := v_sheet_record;
-- Start dates sheet
v_sheet_record.query := v_query_startdate;
v_sheet_record.worksheet_name := 'Start_Dates';
v_sheet_record.col_count := 3;
v_sheet_record.col_width_list := '30,25,22';
v_sheet_record.col_header_list := 'Surname,Given_Name,Start_Date';
v_sheet_collection.EXTEND;
v_sheet_collection(v_sheet_collection.count) := v_sheet_record;
owa.num_cgi_vars := NVL(owa.num_cgi_vars, 0);
reportDocument := DataExportUtils.createExcelDocument(v_sheet_collection);
fileContent := reportDocument.getDocumentData;
v_output_file := UTL_FILE.fopen('C:\\','report.xml','W',4000);
FOR i IN 1 .. fileContent.COUNT LOOP
UTL_FILE.put_line(v_output_file,fileContent(i));
END LOOP;
UTL_FILE.fclose(v_output_file);
END;
Does anyone have insights into what could be causing these style errors while opening the generated file in Excel?