Hello,

I have xlsx spreadsheet which does not have password. My goal is to read
it, add some entries and save as password protected in another (new) file.
After I run my program new file gets password set, but new entries are
absent from it, only original entries are there.  Please help and point out
what I am doing wrong.
I use latest POI 3.17 jars. Below is simplified version of my program
reading empty spreadsheet.
Thanks

public static void main(String[] args) {

      try {
        POIFSFileSystem fs = new POIFSFileSystem();

        EncryptionInfo info = new EncryptionInfo(EncryptionMode.standard);
        Encryptor enc = info.getEncryptor();
        enc.confirmPassword("passw");


        File is = new File("./empty.xlsx");
        OPCPackage opc = OPCPackage.open(is, PackageAccess.READ_WRITE);

        Workbook wb = WorkbookFactory.create(opc);

        Sheet sheet  = wb.getSheetAt(0);
        Row row = sheet.createRow(1);
        Cell cell = row.createCell(1);
        cell.setCellType(Cell.CELL_TYPE_STRING);
        cell.setCellValue("CRYPT");

        OutputStream encos = enc.getDataStream(fs);
        opc.save(encos);
        opc.close();

        OutputStream fos = new FileOutputStream(new File("./f.xlsx"));
        fs.writeFilesystem(fos);
        fos.close();
      }
      catch (Exception ex) {
        System.out.println(ex.getMessage());
        ex.printStackTrace();
      }
    }


----------------------------------------------------------------
Alex Broytman
=========================================================================================================
 <<<< Disclaimer >>>> This message, including all attachments, is private and 
confidential, may contain proprietary or privileged information and material 
and is intended solely for use by the named addressee(s). If you receive this 
transmission in error, please immediately notify the sender and destroy this 
message in its entirety, whether in electronic or hard copy format. Any 
unauthorized use (and reliance thereon), copying, disclosure, retention, or 
distribution of this transmission or the material herein is forbidden. We 
reserve the right to retain, monitor, intercept and archive electronic 
communications. This message does not constitute an offer or solicitation with 
respect to the purchase or sale of any security. It should not be construed to 
contain any recommendation regarding any security or strategy unless expressly 
stated therein. Any reference to the terms of executed transactions should be 
treated as preliminary only and subject to formal written confirmation. Any 
views expressed are those of the individual sender, except where the message 
states otherwise and the sender is authorized to state them to be the views of 
any such entity. This message is provided on an “as is” basis. It contains 
material that is owned by Instinet Incorporated, its subsidiaries or its or 
their licensors, and may not, in whole or in part, be (i) copied, photocopied 
or duplicated in any form, by any means, or (ii) redistributed, posted, 
published, excerpted, or quoted without Instinet Incorporated's prior written 
consent. No confidentiality or privilege is waived or lost by any 
mistransmission of this message. Instinet, LLC (member SIPC) and Instinet 
Canada Limited (member IIROC/CIPF) are subsidiaries of Instinet Incorporated 
that are locally registered or otherwise authorized to provide securities 
brokerage products and services. Please refer to the following links for 
additional disclosures and disclaimers that apply to this message. In the 
United States:  http://instinet.com/docs/legal/le_disclaimers.html . In Canada: 
 http://www.instinet.com/docs/legal/le_ca_disclosures.html . Effective July 1, 
2014, Canada introduced Canadian Anti-Spam Legislation ("CASL"). As a Canadian 
resident you are receiving this electronic communication because of your 
existing relationship with Instinet Canada Limited or an authorized affiliate. 
Canadian residents who wish to unsubscribe from commercial electronic messages: 
please e-mail iclcomplia...@instinet.com. Please note that you will continue to 
receive non-commercial electronic messages, such as account statements, 
invoices, client communications, and other similar factual electronic 
communications. 

=========================================================================================================
 

Reply via email to