Hello,
I am developing application and I use apache poi 3.8 to proceed 2003 and
2007 excel files. One feature that I use is reading each sheet's protection
hash and for 2003 file format I do it with following:
*HSSFWorkbook xlsWb=.....
xlsWb.getSheet(0).getPassword();*
Which works fine for *.xls file, but problem is that I am not able to get
same password hash for 2007 (*.xlsx) format file, because in order to read
*.xlsx file, I use following:
*XSSFWorkbook xssfw = new XSSFWorkbook(is);
xssfw.getSheetAt(0).... // It does not have getPassword() method*
But it does not have method getPassword(); or something which is used to get
password hash from sheet. I solved it with using java.util.zip.* with
following:
*
static int getHashedPassword(File file, int sheetIndex) throws Exception
{
String sheetName = "sheet" + (sheetIndex+1);
InputStream is = new FileInputStream(file);
ZipInputStream zis = new ZipInputStream(is);
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null)
{
if
(entry.getName().toLowerCase().contains(sheetName.toLowerCase()))
{
break;
}
}
int openTagSymbol = ((int) '<');
int closeTagSymbol = ((int) '>');
int character = zis.read();
String password = "";
while (character > 0)
{
String tag = "";
if (character == openTagSymbol)
{
while (character != closeTagSymbol)
{
character = zis.read();
tag += (char) character;
}
if (tag.contains("sheetProtection"))
{
int index = tag.indexOf("password=") +
"password=".length() + 1;
char quotes = '\"';
for (int i = index;; i++)
{
char symbol = tag.charAt(i);
if (symbol == quotes)
{
break;
}
password += symbol;
}
break;
}
}
character = zis.read();
}
return ((password.length() > 0) ? (Integer.parseInt(password, 16)) :
(-1));
}
*
my question is: how can I get protection password hash from *.xlsx file with
using apache POI 3.8? Please give me some samples
--
View this message in context:
http://apache-poi.1045710.n5.nabble.com/Reading-password-hash-from-xlsx-file-tp5710617.html
Sent from the POI - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]