Forum > FPSpreadsheet
Read ods with password?
(1/1)
bonmario:
Hi,
with this code, i can read a file ods without password:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- MyWorkbook:=TsWorkbook.Create; try MyWorkbook.ReadFromFile('PwdNo.ods', sfOpenDocument); MyWorksheet:=MyWorkbook.GetFirstWorksheet; Memo1.Lines.Add('File without password: Col = ' + IntToStr(MyWorksheet.GetLastColIndex(False)) + ' - Row = ' + IntToStr(MyWorksheet.GetLastRowIndex(False))); finally FreeAndNil(MyWorkbook); end;
Now, the same file have been protected with password.
I've tried with the code avove, but it fails:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- MyWorkbook:=TsWorkbook.Create; try MyWorkbook.ReadFromFile('PwdYes_123456.ods', '123456'{, sfOpenDocument}); MyWorksheet:=MyWorkbook.GetFirstWorksheet; Memo1.Lines.Add('File with password: Col = ' + IntToStr(MyWorksheet.GetLastColIndex(False)) + ' - Row = ' + IntToStr(MyWorksheet.GetLastRowIndex(False))); finally FreeAndNil(MyWorkbook); end;
Someone can help me?
Thanks, Mario
wp:
fpspreadsheet does not support encrypted files.
rvk:
You would need to unzip the content of the ods yourself (not protected) and look in the META-INF/manifest.xml. It will show how the files are encrypted (probably aes256-cbc). The initialisation-vector (IV) is also in there. With that you could try to decrypt all the files mentioned in that manifest.xml (a recent post here shows some code to decrypt AES-256-CBC with TDCP_rijndael). After that you can rezip the contents back to an unprotected ods-file and read it with fpspreadsheet. (Don't forget to remove the encryption-data parts in the manifest.xml)
Maybe you also need to do something (PBKDF2) with the password. See https://askubuntu.com/a/223183/926892 for more details.
bonmario:
Ok, thanks
Navigation
[0] Message Index