2013-02-05 14 views
10

मैं एक्सेल फ़ाइल (2007) उत्पन्न करने के लिए अपाचे पीओआई का उपयोग कर रहा हूं। मैं चाहता हूं कि शीट की रक्षा करें, लेकिन कुछ विकल्पों के साथ सक्षम है। विकल्पों के अनुसार मेरा मतलब है कि जब आप Excel अनुप्रयोग में शीट की रक्षा करने का प्रयास करते हैं तो चेक बॉक्स सूची (लेबल के अंतर्गत "इस वर्कशीट के सभी उपयोगकर्ताओं को निम्न अनुमति दें:")। विशेष रूप से, मैं "लॉक/अनलॉक सेल का चयन करें", "प्रारूप कॉलम", "सॉर्ट करें" और "ऑटोफिल्टर को अनुमति दें" सक्षम करना चाहता हूं। आपका बहुत बहुत धन्यवाद! : डीअपाचे पीओआई - विकल्पों के साथ शीट की रक्षा कैसे करें?

+0

मुझे नहीं 'sheet.getSettings()' सेट() पद्धतियों से परे लगता है, तो आप कुछ भी कर सकते हैं। – TheWhiteRabbit

+0

sheet.getSettings() जेएक्ससेल से है, अपाचे पीओआई नहीं, मुझे लगता है। – Jairo

उत्तर

10

अपाचे पीओआई 3.9 में आप लॉक फ़ंक्शंस को सक्षम करके XSSF शीट सुरक्षा का उपयोग कर सकते हैं। यहां तक ​​कि आप नीचे दिए गए कुछ एक्सेल ऑब्जेक्ट्स को पीछे छोड़ सकते हैं जैसे कि मैंने एक्सेल ऑब्जेक्ट (यानी टेक्स्ट बॉक्स) अनलॉक किया है और बाकी लॉक हैं।

private static void lockAll(Sheet s, XSSFWorkbook workbookx){ 
    String password= "abcd"; 
    byte[] pwdBytes = null; 
    try { 
     pwdBytes = Hex.decodeHex(password.toCharArray()); 
    } catch (DecoderException e) { 
     e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 
    } 
    XSSFSheet sheet = ((XSSFSheet)s); 
    removePivot(s,workbookx); 
    sheet.lockDeleteColumns(); 
    sheet.lockDeleteRows(); 
    sheet.lockFormatCells(); 
    sheet.lockFormatColumns(); 
    sheet.lockFormatRows(); 
    sheet.lockInsertColumns(); 
    sheet.lockInsertRows(); 
    sheet.getCTWorksheet().getSheetProtection().setPassword(pwdBytes); 
    for(byte pwdChar :pwdBytes){ 
     System.out.println(">>> Sheet protected with '" + pwdChar + "'"); 
    } 
    sheet.enableLocking(); 

    workbookx.lockStructure(); 

} 
5

आपको लगता है कि आप कौन सी विशेषताओं का चयन नहीं कर सकते हैं, यह सब कुछ या कुछ भी नहीं है। यह वर्तमान में अपाचे पोई में एक ज्ञात बग है। स्रोत: https://issues.apache.org/bugzilla/show_bug.cgi?id=51483

आप नीचे दिए गए वैकल्पिक हल का उपयोग करके इसे ठीक कर सकते हैं:

xssfSheet.enableLocking(); 
    CTSheetProtection sheetProtection = xssfSheet.getCTWorksheet().getSheetProtection(); 
    sheetProtection.setSelectLockedCells(true); 
    sheetProtection.setSelectUnlockedCells(false); 
    sheetProtection.setFormatCells(true); 
    sheetProtection.setFormatColumns(true); 
    sheetProtection.setFormatRows(true); 
    sheetProtection.setInsertColumns(true); 
    sheetProtection.setInsertRows(true); 
    sheetProtection.setInsertHyperlinks(true); 
    sheetProtection.setDeleteColumns(true); 
    sheetProtection.setDeleteRows(true); 
    sheetProtection.setSort(false); 
    sheetProtection.setAutoFilter(false); 
    sheetProtection.setPivotTables(true); 
    sheetProtection.setObjects(true); 
    sheetProtection.setScenarios(true); 
+0

मैं XSSFSheet ऑब्जेक्ट का उपयोग कर रहा हूं। क्या मेरे शीट को सुरक्षित रखने के साथ एक्सेल में सभी फ़िल्टर विकल्प साफ़ करने में सक्षम करने का कोई तरीका है। कोई सुझाव ? –

संबंधित मुद्दे