Convert xlsx to xls

350 views
Skip to first unread message

Senthil Kumar TM

unread,
May 4, 2012, 3:40:19 AM5/4/12
to JODConverter
I want to convert xlsx to xls. Could you please provide me the sample
code?

Oleksii Kyslytsyn

unread,
Jul 31, 2015, 5:38:29 AM7/31/15
to JODConverter, tmsenth...@gmail.com
byte[] hssSheetBytes = null;
        if (xlsx) {
            System.out.println("hey we are here");

            ByteArrayOutputStream bout = new ByteArrayOutputStream();

            byte[] workbookBytes = bout.toByteArray();

            File tempXlsxFile = File.createTempFile("XLSX", ".xlsx");
            File tempXlsFile = File.createTempFile("XLS", ".xls");

            FileOutputStream fos = new FileOutputStream(tempXlsxFile);
            fos.write(workbookBytes);

            OfficeManager officeManager = new DefaultOfficeManagerConfiguration().buildOfficeManager();
            officeManager.start();

            OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);
            converter.convert(tempXlsxFile, tempXlsFile);

            officeManager.stop();
            // Desktop.getDesktop().open(tempXlsxFile);
            // Desktop.getDesktop().open(tempXlsFile);
            System.out.println("hey we are still here yay!");
            fos.close();

            byte[] convertedXlsFileBytes = FileUtils.readFileToByteArray(tempXlsFile);
            hssSheetBytes = new byte[convertedXlsFileBytes.length];
            System.arraycopy(convertedXlsFileBytes, 0, hssSheetBytes, 0, convertedXlsFileBytes.length);
Reply all
Reply to author
Forward
0 new messages