Writing to an Excel(xlsx,2007 format) using PL/SQL

Hi,
I have a new requirement in which I have to write to an excel ,.xlsx(2007 format). I am using Oracle 9i.
When I try to write it to .xlsx it is writing but when i try to open the file it says "excel 2007 excel cannot open the file because the file format or file extension is not valid".
I am using the following Stored Procedure:
create or replace
procedure myfilewrite( p_location IN varchar2,
p_filename IN varchar2)
IS
v_disk_file utl_file.file_type;
BEGIN
v_disk_file := utl_file.fopen( location => p_location,
filename =>p_filename,
open_mode=>'W');
utl_file.put_line(v_disk_file,'abc'||chr(13));
utl_file.fclose(v_disk_file);
EXCEPTION
when utl_file.invalid_path then
utl_file.fclose(v_disk_file);
raise_application_error(-2001,'path error');
when utl_file.invalid_operation then
utl_file.fclose(v_disk_file);
raise_application_error(-2002,'invalid operation error');
when utl_file.write_error then
utl_file.fclose(v_disk_file);
raise_application_error(-2003,'write error');
when utl_file.invalid_filehandle then
utl_file.fclose(v_disk_file);
raise_application_error(-2004,'filehandler error');
when others then
raise_application_error(-2005,'could not write to file');
END;
Please help me regarding this issue.
Regards,
RAJ

user13529315 wrote:
In the existing application we have been writing into .xls format using utl_file package.No you haven't. You have been writing a file in CSV format that is named with an XLS extension. File name does not equal file format, XLS is a binary format, UTL_FILE cannot write binary files.
CSV - http://en.wikipedia.org/wiki/Comma-separated_values
>
A comma-separated values or character-separated values (CSV) file is a simple text format
>
XLS - http://en.wikipedia.org/wiki/Microsoft_Excel_file_format#File_formats
>
Microsoft Excel up until 2007 version used a proprietary binary file format called Binary Interchange File Format (BIFF) as its primary format.

Similar Messages

  • Writing a file in UTF-8 Format using FileWriter

    Hi,
    I am trying to write some data to the file system using a filewriter object. I want the file to be stored in UTF-8 encoding. Please give me some pointers regarding the same.
    Best Regards,
    Pradeep

    First you have to declare that you will use UTF8 :
    OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(myFilePath,true),"UTF8");Then you can write in you file in UTF8.
    The problem is that when you open the file with an editor like Crimson or UltraEdit, it says that your file is encoded in ASCII ... even if your stream had well been saved in UTF8.
    To be sure that your file format is UTF8, you have to had at the beginning of your file 3 bytes : EF, BB and BF :
    byte[] x = new byte[3];
    x[0] = (byte) (Integer.parseInt("EF",16));
    x[1] = (byte) (Integer.parseInt("BB",16));
    x[2] = (byte) (Integer.parseInt("BF",16));
    osw.write(new String(x,"UTF8"));Here my "complete" code :
    String myFilePath = "........";
    String myText = "............";
    OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(myFilePath,true),"UTF8");
    System.err.println("osw encoding : "+osw.getEncoding()); //just to be sure of the encoding
    byte[] x = new byte[3];
    x[0] = (byte) (Integer.parseInt("EF",16));
    x[1] = (byte) (Integer.parseInt("BB",16));
    x[2] = (byte) (Integer.parseInt("BF",16));
    osw.write(new String(x,"UTF8"));
    osw.write(new String(myText));
    osw.close();I think you can use OutputStreamWriter instead of FileWriter as FileWriter inherits of OutputStreamWriter.

  • How to get currency format using pl sql function

    Hi all,
    I am a newbee on the forum. currently i am facing an issue with the Format of Currency in an rdf report. This is a field of tax amount & i need to make some conditional formatting on this like if the tax amount is Zero then some static note is to be added before this field.
    I have tried a lot of functions on it like the one as below:
    IF :cp_org_id = 102
    AND :invoice_currency_code <> 'CAD'
    AND TO_CHAR (NVL (:cf_tax_amount, 0)) = 0
    THEN
    RETURN (TRUE);
    ELSE
    RETURN (FALSE);
    This is working fine in case of Zero tax amount But gets error out when there some Tax amount exists. It gives a VALUE ERROR in this format Trigger.
    Kindly suggest me how to solve this issue with right function. If possible then write the pseudo Code also.
    Thanks in advance
    D_Verma

    In addition to Satyaki:
    It might be a 'Reports Thing'.
    It works in SQL*Plus (although relying on implicit conversions is a bad idea, as mentioned):
    MHO%xe> begin
      2  IF 102 = 102
      3  AND 'DAC' != 'CAD'
      4  AND TO_CHAR (NVL (null, 0)) = 0
      5  THEN
      6  dbms_output.put_line('TRUE');
      7  ELSE
      8  dbms_output.put_line('FALSE');
      9  end if;
    10  end;
    11  /
    TRUE
    PL/SQL-procedure is geslaagd.
    MHO%xe> begin
      2  IF 102 = 102
      3  AND 'DAC' != 'CAD'
      4  AND TO_CHAR (NVL (0, 0)) = 0
      5  THEN
      6  dbms_output.put_line('TRUE');
      7  ELSE
      8  dbms_output.put_line('FALSE');
      9  end if;
    10  end;
    11  /
    TRUE
    PL/SQL-procedure is geslaagd.
    MHO%xe> begin
      2  IF 102 = 102
      3  AND 'DAC' != 'CAD'
      4  AND TO_CHAR (NVL ('0', '0')) = '0'
      5  THEN
      6  dbms_output.put_line('TRUE');
      7  ELSE
      8  dbms_output.put_line('FALSE');
      9  end if;
    10  end;
    11  /
    TRUE
    PL/SQL-procedure is geslaagd.

  • Need to generate excel(or CSV format) report using Oracle10g PL/SQL

    Hi Guys,
    I want to generate excel/csv report dynamically using PL/SQL, as I am presently running one SQL query to fetch results and extract excel file. This I need to do dynamically by using PL/SQL code.
    Also the generated file need to send to couple of recepients via mail, this process shall I do it from Oracle ?
    Can any body help on this.
    Thanks in advance!!
    Regards,
    KLR

    UTL_FILE
    UTL_MAIL
    https://forums.oracle.com/thread/2609119
    Ramin Hashimzade

  • Getting the schema using Oracle SQL Developer 1.5.1

    I need to generate a report in CSV/XLS format using Oracle SQL Developer 1.5.1 to get the schema details
    in the below format.
    Table Name: XXXXXXXXX
    Table Space Name: XXXXXXXXXXXXXXX
    Structure :
    Field Name Data Type Size
    Xxxxxxxx xxxxxx xxxxx
    Xxxxxxxx xxxxxx xxxxx
    Xxxxxxxx xxxxxx xxxxx
    Xxxxxxxx xxxxxx xxxxx
    Field level constraint:
    Xxxxxxxxxxxxxxxxxx
    Table Level Constraint:
    Xxxxxxxxxxxxxxxxxx
    Indexes:
    Index Name Column Name(s) Table space name
    Xxxxxxxx xxxxxxxxx xxxxxxxxxxxx
    Xxxxxxxx xxxxxxxxx xxxxxxxxxxxx
    Xxxxxxxx xxxxxxxxx xxxxxxxxxxxx
    Sequence Number:
    Xxxxxxxxxxxxxxxx
    Triggers:
    Xxxxxxxxxxxxxxxxxx
    I am using a query to do that, but I cannot run more than one queries in the Create Report Dialog.
    I went to the Menu->View->Reports. In that, I chose User Defined Reports, created a new folder called Schema Detail and in that a report named Schema Detail. I right click on that report, choose Edit option, Create Report Dialog opens.
    In the Create Report Dialog, I chose the option Script for Value of Style.
    In the SQL column I enter a query "select * from table_names". But, if I enter another query after that, it does not run and reports an error "SQL Error: ORA-00933: SQL command not properly ended
    00933. 00000 - SQL command not properly ended" Cause:    Action: "
    I end the first query with a semi colon, but it does not work.
    The queries run fine in a SQL Worksheet. There, I can terminate the first query with a semi colon and enter the second query. Then, I run both of them together so that result-set of second query appears after the second.
    Am I doing something wrong? Can someone please advise on how to get the information I need?
    Thanks a lot.

    You can do it in SQL Worksheet because you are running a script. You could run the script in SQL*Plus, and even start it from a bat/cmd file.
    Or if you want this as a User Defined Report, you might make it a PL/SQL style report. Here, all output is done through DBMS_OUTPUT.PUT or DBMS_OUTPUT.PUT_LINE. You can output HTML tags or plain text. I have an example in my paper for ODTUG Kaleidoscope 2009.

  • Writing into Excel file using PL/SQL and formatting the excel file

    Hi,
    I am writing into a excel file using PL/SQL and I want to make the first line bold on the excel. Also let me know if there are any other formatting options when writing into excel.
    Regards,
    -Anand

    I am writing into a excel file using PL/SQL
    Re: CSV into Oracle and Oracle into CSV
    check that thread or search in this forum...

  • Useful code for exporting to Excel xlsx

    I wanted to "give back" by posting this little code sample for exporting a query into Excel xlsx
    Kudos to Charlie Arehart for helping me increase the server memory and java heap size.
    This code works for me using CF 9 on Windows Server 2008 R2. By the way, CFSpreadsheet seems to consume a lot of memory on larger exports. For this reason, we increased the server's physical memory, then used CF Administrator to increase the jvm heap size in the Administrator -> Java and JVM settings. My max java heap size is now 3072.
    Need help? I recommend you contact Charlie Arehart on server issues: [email protected]
    Code:
    Example query is called "Myquery" Spreadsheet is called "Myspreadsheet" I export the spreadsheet to a subdirectory called "xlsx" I use cflocation to direct the browser to the spreadsheet. The browser prompts the user to open, save or cancel.
    <cfset var_filenameis = "Myspreadsheet.xlsx">
    <cfset SpreadsheetObj = spreadsheetNew("true")>
    <cfset SpreadsheetObj = spreadsheetNew("#var_filenameis#","yes")>
    <cfspreadsheet action="write" filename="./xlsx/#var_filenameis#" query="Myquery" overwrite="true">
    <cflocation url = "./xlsx/#var_filenameis#">    

    An inline DataTable is not the same thing as exporting data in a standardized XLSX format.  (I'll post the script I use in another comment.
    Regarding inline tables, here are some other worth scripts:
    Handsontable - minimalistic Excel-like data grid editor
    http://handsontable.com/
    TableSorter 2 (forked) - sorting, filtering, grouping, pagination, inline editing, sticky header
    http://mottie.github.io/tablesorter/docs/
    jQuery Grid Plugin
    http://paramquery.com/
    jQuery table to CSV
    http://www.kunalbabre.com/projects/table2CSV.php
    jQuery Pivot - presenting table data in pivot form
    http://metalogic.dk/jquery.pivot/demo.htm

  • Problem in writing into the excel file using java code

    Hai ,
    I will be getting the data as a string and i am writing into the excel file. the problem is .if it has numeric values even now i will writing as a string data ,at this time i am getting the message in the excel file as "Number in the cell is formatted as text".
    I need to remove this thru my code..but i can write only as a string .
    To write in a excel file ,i used HSSFWorkbook.

    just check out
    http://www.andykhan.com/

  • Enable Excel 2007 format export on Crystal Reports Server 2008 - Sharepoint

    I'm trying to use Sharepoint's excel services to post some charts from an exported Crystal report to sharepoint.  However Crystal Reports Server 2008 only exports excel 97-2003 format.  How can I update the Crystal Reports Server 2008 components to support Excel 2007 format.  Has anyone done this before?
    Thanks,
    Dominic

    Unfortunately what you are looking for is not possible (At least as far as I know).  Crystal is limited to the formats that it already has - and it is not possible to add additional export formats.
    Sorry
    Shawn

  • How can i convert oracle report in excel format using 8i

    hi,
    I want to convert oracle report in excel format using 6i reports. please give the solution with emp table.
    millons of thanks in advance.

    You'll have to use the destype DELIMITEDDATA to render your Report in CSV format. Then set the mime type to Excel. I don't know the exact syntax, so please do a search in metalink for "reports excel" for examples and more info.
    Regards,
    Martin Malmstrom

  • The numbering format keeps changing when making PDF's from Word 2007 ? Using Acrobat 9 Pro Extended

    The numbering in (Contents) format keeps changing when making PDF's from Word 2007 ? Using Acrobat 9 Pro Extended.

    The issue is that I have made up a contract in Word.
    The second page has a list of all contents of the contract.
    gghhjhhbhbhhbhbjbhj....1
    bv v vghvjvjnnnnnnnnn....2
    When we convert to PDF some of the numbers change. Example 20 becomes 201.
    Your help is appreciated.
    Cheers Ocean designs.

  • Where do I start writing Office (Word & Excel) Addins using VS 2013 Community?

    First, I hope that I have selected the appropriate location for this message. If not I apologize. I am hoping that posting to the VSTO  community will also cover the Word and Excel development groups.
    Second, a word of explanation: I am partially handicapped (unable to use my left hand easily), and 73 years of age and retired, and due to medical prescriptions unable to respond as quickly as I might desire.
    Consequently I may be tardy in responding to any messages sent to me.
    SUBJECT: I currently have Office 2007 (and as a limited income retiree - find it impossible to upgrade to a newer version of Office) and would like to prepare/write some add-ins of the macros (VBA for both
    Word and Excel) that I have used and developed over the years. When I retired I lost the opportunity to use advanced versions of Visual Studio and have been limited to the "Express" versions of Visual Studio. With the recent release of Visual
    Studio 2013 Community there appears to be the possibility that I might be able to convert my macros and such to an add-in. Unfortunately, I haven't a clue where or even how to start.
    I very much would appreciate any information, directions, suggestions, and ideas which might help me find a way to get started in providing an add-in which would span the various versions of Word and Excel between 2007 and the current version. (I am currently
    running Windows 8.1 but must admit I am not terribly impressed.)
    I might note that my primary language for programming has been VB (as in VBA). I am not opposed to learning C# but rewriting everything would be a bit more inefficient than I would like to tackle at this point in time.
    If there is some generous soul who would be kind enough to point me toward articles, samples/examples, and ideas on how I might be able to create these add-ins of my macros and such I would be deeply appreciative.
    NOTE: I realized only after making the original post that I forgot to ask whether I need to obtain a copy of VSTO or whether the capabilities of VSTO had been incorporated into Visual Studio 2013 Community.
    David Schrader
    [email protected]
    David (Whose retirement hasn't been as exciting as I was lead to believe it would be.)

    Hello David,
    Out of the box the Community edition of VS doesn't include VSTO templates. You have to install
    http://aka.ms/OfficeDevToolsForVS2013 to get them appear. In general, the Community edition corresponds to the Professional one (paid one). So, you can start developing add-ins in VB.NET. See
    Create Add-ins and Customizations for Office by using Visual Studio for more information.

  • Problems with Excel xlsx files and Presentation Design 2011

    Hello,
    I just began using Presentation Design 2011 and have run into an issue and would really appreciate your help.
    I have very large files in Excel 2007 format (.xlsx) that I need to import into Presentation Design.  When I try to do so, it automatically opens the .xlsx file as a 97-2003 Excel file, and in hte process, I then lose a large portion of the data (the file is very large, and the space limitations in 97-2003 are not sufficient for all the data I have, so I receive a message about compatability indicating that the data goes beyond the space limit).
    I have tried looking online for a fix to this issue, and I cannot find it.  I just installed the service pack 2 patch 8 file, and this still does not work.
    Will someone please let me know what I need to download or do to be able to import the xlsx files and maintain them in that format? 
    Thank you!
    Curtis

    Hi Curtis,
    In the older version of dashboard design 2011, xcelsius 2008, .xlsx(excel 2007) files are imported and converted automatically to excel 2003 format. So there are some compatiability issues with both versions and also size limitations. excel 2003 cannot have more than 256 columns. I doubt same is the case with new version.
    Inside the designer data is in excel 2003 format. So you cannot have data more than the limit and some formats. You should only be pulling in enough data to fill your components in dashboard and remove any unnessary information from the spreadsheet . Since dashboards are meant for summary data, importing very large excels files are not recommended.
    Hope it helps you.
    Regards,
    Nikhil Joy

  • Export to PDF, Excel, Excel (Data Only) formatting issues

    Hi Community
    I have a report that consists of 5 subreports. Out of the 5 subreports, 3 of them have a similar format whereas the other 2 are different.
    Iu2019m currently facing an issue whereby the exports to excel works fine, but excel (data only) has some alignment issues(i.e. the data appears below the correct columns). However, when the report is tweaked to make export to excel (data only) appear correctly, the export to excel had its data shifted out of alignment. There is no impact to pdf exporting at the moment.
    Are there any people who are facing similar issues? Is there any resolution or workaround? I appreciate any help. Thanks.
    FYI, the version of crystal reports is Crystal reports is Crystal reports 2008 and we are using the crystal report viewer interface to export into excel and pdf formats. The excel version is 2007.
    Regards

    DW, i've also run into issues with multiple sub reports. I resolved it by putting each sub report into it's own section, and then suppressing the sub report (Note, if ur trying to export subreport data to excel, I don't think its going to work. You'd need to create shared variables and then bring those sub report shared variables into your main report).
    Once you bring your shared variables into the main report, suppress your sub reports, and then export to excel, you're still left with a dataset that has missing rows. This is ok. You can solve it easily within the excel file itself by sorting the data on a unique ID like Account #. This removes the extra rows.
    Not the most elegant solution, but it works.

  • Change Excel sheet tab color using Open XML dll

    Hi,
    I want to change the sheet tab color of an excel Xlsx  document. I am using the following code but it does not set the sheet color. I get object reference exception when I set the sheet tab color.
    public static string filepath = @"C:\Test\Book1.xlsx";
    private static void ChangeSheetcolor()
    try
    using (SpreadsheetDocument spreadSheetDocument = SpreadsheetDocument.Open(filepath, false))
    WorkbookPart workbookPart = spreadSheetDocument.WorkbookPart;
    IEnumerable<Sheet> sheets = spreadSheetDocument.WorkbookPart.Workbook.GetFirstChild<Sheets>().Elements<Sheet>();
    //my code
    WorksheetPart worksheetPart =
    GetWorksheetPartByName(spreadSheetDocument, "Sheet1");
    if (worksheetPart != null)
    // worksheetPart.Worksheet.SheetProperties.TabColor.Rgb = DocumentFormat.OpenXml.HexBinaryValue.FromString("Red");
    worksheetPart.Worksheet.SheetProperties.TabColor.Rgb = DocumentFormat.OpenXml.HexBinaryValue.FromString("#CCCCCC");
    // Save the worksheet.
    worksheetPart.Worksheet.Save();
    catch (Exception ex)
    private static WorksheetPart
    GetWorksheetPartByName(SpreadsheetDocument document,
    string sheetName)
    IEnumerable<Sheet> sheets =
    document.WorkbookPart.Workbook.GetFirstChild<Sheets>().
    Elements<Sheet>().Where(s => s.Name == sheetName);
    if (sheets.Count() == 0)
    //does not exist
    return null;
    string relationshipId = sheets.First().Id.Value;
    WorksheetPart worksheetPart = (WorksheetPart)
    document.WorkbookPart.GetPartById(relationshipId);
    return worksheetPart;
    How to change the sheet tab color using Open XML dlls.
    Thanks
    Ashok

    Hi J_Prasanna,
    I'm afraid that it's not possible with OpenXML SDK, but it's possible if you use Excel PIA along with Internet Explorer. Use the Internet Explorer COM object to render the HTML content, then copy the document, use the Paste method of the Worksheet object
    to paste the text with format.
    Dim IE As Object
    Set IE = CreateObject("InternetExplorer.Application")
    With IE
    .Visible = False
    .Navigate "about:blank"
    .document.body.InnerHTML = Sheets("Sheet1").Range("A1").Value
    .document.body.createtextrange.execCommand "Copy"
    ActiveSheet.Paste Destination:=Sheets("Sheet1").Range("A1")
    .Quit
    End With
    The code is similar if you use managed project.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

Maybe you are looking for