本文整理匯總了Java中org.apache.poi.hssf.record.crypto.Biff8EncryptionKey類的典型用法代碼示例。如果您正苦於以下問題:Java Biff8EncryptionKey類的具體用法?Java Biff8EncryptionKey怎麽用?Java Biff8EncryptionKey使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Biff8EncryptionKey類屬於org.apache.poi.hssf.record.crypto包,在下文中一共展示了Biff8EncryptionKey類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: importTables
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; //導入依賴的package包/類
/**
* core code
*
* @param stream asset stream or file stream
* @param fileName origin file name
* @throws Exception
*/
private boolean importTables(InputStream stream, String fileName) throws Exception {
Workbook workbook;
if (fileName.toLowerCase().endsWith(".xls")) {
if (!TextUtils.isEmpty(decryptKey)) {
Biff8EncryptionKey.setCurrentUserPassword("1234567");
}
workbook = new HSSFWorkbook(stream);
} else {
throw new UnsupportedOperationException("Unsupported file format!");
}
stream.close();
int sheetNumber = workbook.getNumberOfSheets();
for (int i = 0; i < sheetNumber; i++) {
createTable(workbook.getSheetAt(i));
}
database.close();
return true;
}
示例2: decrypt
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; //導入依賴的package包/類
/**
* When HSSF receive encrypted file, it tries to decode it with MSOffice
* build-in password. Use static method setCurrentUserPassword(String
* password) of org.apache.poi.hssf.record.crypto.Biff8EncryptionKey to set
* password. It sets thread local variable. Do not forget to reset it to
* null after text extraction.
*
* (http://poi.apache.org/encryption.html)
*
* @param input
* @param password
* @return
* @throws IOException
*/
public static HSSFWorkbook decrypt(InputStream input, String password)
throws IOException {
try {
Biff8EncryptionKey.setCurrentUserPassword(password);
return new HSSFWorkbook(input);
} catch (Exception ex) {
throw new RuntimeException("Unable to process encrypted document",
ex);
} finally {
Biff8EncryptionKey.setCurrentUserPassword(null);
}
}
示例3: finalizeWriteEncryptedHSSF
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; //導入依賴的package包/類
private void finalizeWriteEncryptedHSSF() throws IOException {
LOG.debug("encrypting HSSFWorkbook");
Biff8EncryptionKey.setCurrentUserPassword(this.howc.getPassword());
try {
this.currentWorkbook.write(this.oStream);
} finally {
Biff8EncryptionKey.setCurrentUserPassword(null);
if (this.oStream!=null) {
this.oStream.close();
}
}
}
示例4: EncryptFile
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; //導入依賴的package包/類
/**
* Encrypt a file, support .xls file only
*
* @param file
* @param encryptKey
* @throws Exception
*/
public static void EncryptFile(File file, String encryptKey) throws Exception {
FileInputStream fileInput = new FileInputStream(file.getPath());
BufferedInputStream bufferInput = new BufferedInputStream(fileInput);
POIFSFileSystem poiFileSystem = new POIFSFileSystem(bufferInput);
Biff8EncryptionKey.setCurrentUserPassword(encryptKey);
HSSFWorkbook workbook = new HSSFWorkbook(poiFileSystem, true);
FileOutputStream fileOut = new FileOutputStream(file.getPath());
workbook.writeProtectWorkbook(Biff8EncryptionKey.getCurrentUserPassword(), "");
workbook.write(fileOut);
bufferInput.close();
fileOut.close();
}