Çalışma Sayfasını Koru ve Korumayı Kaldır
Çalışma Sayfalarını Koruyun
Bir çalışma sayfası korunduğunda, kullanıcının yapabileceği işlemler kısıtlanır. Örneğin, veri giremez, satır veya sütun ekleyemez veya silemezler vb. Microsoft Excel’deki genel koruma seçenekleri şunlardır:
- İçindekiler
- nesneler
- senaryolar
Korumalı çalışma sayfaları hassas verileri gizlemez veya korumaz, dolayısıyla dosya şifrelemeden farklıdır. Genel olarak, çalışma sayfası koruması sunum amaçları için uygundur. Son kullanıcının çalışma sayfasındaki verileri, içeriği ve biçimlendirmeyi değiştirmesini engeller.
Koruma Ekleme veya Kaldırma
Aspose.Cells bir sınıf sağlar,Çalışma kitabı , bu bir Microsoft Excel dosyasını temsil eder. Workbook sınıfı, bir Excel dosyasındaki her çalışma sayfasına erişmeye izin veren bir WorksheetCollection içerir. Bir çalışma sayfası şununla temsil edilir:Çalışma kağıdı sınıf.
Worksheet sınıfı şunları sağlar:Korumak bir çalışma sayfasına koruma uygulamak için kullanılan yöntem. Protect yöntemi aşağıdaki parametreleri kabul eder:
- Koruma Türü, çalışma sayfasına uygulanacak koruma türü. Koruma türü yardımı ile uygulanır.Koruma Türü numaralandırma.
- Yeni Parola, çalışma sayfasını korumak için kullanılan yeni parola.
- Eski Parola, eski parola, eğer çalışma sayfası zaten parola korumalıysa. Çalışma sayfası zaten korumalı değilse, sadece bir boş değer iletin.
ProtectionType numaralandırması, aşağıdaki önceden tanımlanmış koruma türlerini içerir:
Koruma Türleri | Açıklama |
---|---|
HERŞEY | Kullanıcı bu çalışma sayfasındaki hiçbir şeyi değiştiremez |
İÇİNDEKİLER | Kullanıcı bu çalışma sayfasına veri giremez |
NESNELER | Kullanıcı çizim nesnelerini değiştiremez |
SENARYOLAR | Kullanıcı kaydedilen senaryoları değiştiremez |
YAPI | Kullanıcı kaydedilen yapıyı değiştiremez |
PENCERELER | Kullanıcı kaydedilen pencereleri değiştiremez |
YOK | Koruma yok |
Aşağıdaki örnek, bir çalışma sayfasının parola ile nasıl korunacağını gösterir.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ProtectingWorksheet.class) + "worksheets/"; | |
// Instantiating a Excel object by excel file path | |
Workbook excel = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
WorksheetCollection worksheets = excel.getWorksheets(); | |
Worksheet worksheet = worksheets.get(0); | |
Protection protection = worksheet.getProtection(); | |
// The following 3 methods are only for Excel 2000 and earlier formats | |
protection.setAllowEditingContent(false); | |
protection.setAllowEditingObject(false); | |
protection.setAllowEditingScenario(false); | |
// Protects the first worksheet with a password "1234" | |
protection.setPassword("1234"); | |
// Saving the modified Excel file in default format | |
excel.save(dataDir + "ProtectingWorksheet_out.xls"); | |
// Print Message | |
System.out.println("Sheet protected successfully."); |
Çalışma sayfasını korumak için yukarıdaki kod kullanıldıktan sonra, çalışma sayfasını açarak korumayı kontrol edin. Dosyayı açıp çalışma sayfasına bazı veriler eklemeye çalıştığınızda, aşağıdaki iletişim kutusu görüntülenir:
Bir kullanıcının çalışma sayfasını değiştiremeyeceğini belirten bir iletişim kutusu uyarısı
Çalışma sayfası üzerinde çalışmak için, çalışma sayfasını seçerek korumayı kaldırın.Koruma , o zamanlarSayfanın korumasını kaldır danAraçlar Menü öğesi aşağıda gösterildiği gibi.
Sayfanın Korumasını Kaldır menü öğesini seçme
Parola isteyen bir iletişim kutusu açılır.
Çalışma sayfasının korumasını kaldırmak için parola girme
Birkaç Kişiyi Korumak Cells
Çalışma sayfasında yalnızca birkaç hücreyi kilitlemeniz gereken belirli senaryolar olabilir. Çalışma sayfasındaki bazı belirli hücreleri kilitlemek istiyorsanız, çalışma sayfasındaki diğer tüm hücrelerin kilidini açmanız gerekir. Bir çalışma sayfasındaki tüm hücreler zaten kilitleme için başlatılmıştır, bu herhangi bir excel dosyasını MS Excel’e açıp kontrol edebilirsiniz.Biçim | Cells… göstermek içinBiçim Cells iletişim kutusunu tıklayın ve ardından Koruma sekmesini tıklayın ve “Kilitli” etiketli bir onay kutusunun varsayılan olarak işaretli olduğunu görün.
Görevi uygulamak için iki yaklaşım aşağıdadır.
Yöntem 1:
Aşağıdaki noktalar, MS Excel kullanılarak birkaç hücrenin nasıl kilitleneceğini açıklamaktadır. Bu yöntem Microsoft Office Excel 97, 2000, 2002, 2003 ve üzeri sürümler için geçerlidir.
- Tümünü Seç düğmesini (1. satır için satır numarasının hemen üzerindeki ve A sütun harfinin solundaki gri dikdörtgen) tıklatarak tüm çalışma sayfasını seçin.
- Biçim menüsünde Cells’e tıklayın, Koruma sekmesine tıklayın ve ardından Kilitli onay kutusunun işaretini kaldırın.
Bu, çalışma sayfasındaki tüm hücrelerin kilidini açar
- Yalnızca kilitlemek istediğiniz hücreleri seçin ve 2. adımı tekrarlayın, ancak bu sefer Kilitli onay kutusunu seçin.
- ÜzerindeAraçlar menü, seçKoruma , TıklayınSayfayı Koruyun ve ardından tıklayınTamam.
Yöntem2:
Bu yöntemde sadece görevi yapmak için Aspose.Cells API kullanıyoruz.
Aşağıdaki örnek, çalışma sayfasındaki birkaç hücrenin nasıl korunacağını gösterir. Önce çalışma sayfasındaki tüm hücrelerin kilidini açar ve ardından çalışma sayfasındaki 3 hücreyi (A1, B1, C1) kilitler. Son olarak, çalışma sayfasını korur. Bir satır/sütun, ayrıca bir dizi Kilitli yöntemi içeren bir Stil API’e sahiptir. Satırı / sütunu kilitlemek veya kilidini açmak için bu yöntemi kullanabilirsiniz.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ProtectingSpecificCellsinaWorksheet.class) + "worksheets/"; | |
// Create a new workbook. | |
Workbook wb = new Workbook(); | |
// Create a worksheet object and obtain the first sheet. | |
Worksheet sheet = wb.getWorksheets().get(0); | |
// Define the style object. | |
Style style; | |
// Define the styleflag object. | |
StyleFlag flag; | |
flag = new StyleFlag(); | |
flag.setLocked(true); | |
// Loop through all the columns in the worksheet and unlock them. | |
for (int i = 0; i <= 255; i++) { | |
style = sheet.getCells().getColumns().get(i).getStyle(); | |
style.setLocked(false); | |
sheet.getCells().getColumns().get(i).applyStyle(style, flag); | |
} | |
// Lock the three cells...i.e. A1, B1, C1. | |
style = sheet.getCells().get("A1").getStyle(); | |
style.setLocked(true); | |
sheet.getCells().get("A1").setStyle(style); | |
style = sheet.getCells().get("B1").getStyle(); | |
style.setLocked(true); | |
sheet.getCells().get("B1").setStyle(style); | |
style = sheet.getCells().get("C1").getStyle(); | |
style.setLocked(true); | |
sheet.getCells().get("C1").setStyle(style); | |
// Save the excel file. | |
wb.save(dataDir + "PSpecificCellsinaWorksheet_out.xls", FileFormatType.EXCEL_97_TO_2003); | |
// Print Message | |
System.out.println("Cells protected successfully."); |
Çalışma Sayfasında Bir Satırı Koruma
Aspose.Cells, çalışma sayfasındaki herhangi bir satırı kolayca kilitlemenizi sağlar. Burada, kullanabilirizApplyStyle() yöntemiSıra çalışma sayfasındaki belirli bir satıra Stil uygulamak için sınıf. Bu yöntem iki argüman alır: astil nesne veStil Bayrağı Uygulanan biçimlendirme ile ilgili tüm üyeleri içeren yapı.
Aşağıdaki örnek, çalışma sayfasındaki bir satırın nasıl korunacağını gösterir. Önce çalışma sayfasındaki tüm hücrelerin kilidini açar ve ardından ilk satırı kilitler. Son olarak, çalışma sayfasını korur. Bir satır/sütun, ayrıca bir setCellLocked yöntemi içeren bir Stil API’e sahiptir. StyleFlag yapısını kullanarak satırı / sütunu kilitleyebilir veya kilidini açabilirsiniz.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ProtectRowWorksheet.class) + "worksheets/"; | |
// Create a new workbook. | |
Workbook wb = new Workbook(); | |
// Create a worksheet object and obtain the first sheet. | |
Worksheet sheet = wb.getWorksheets().get(0); | |
// Define the style object. | |
Style style; | |
// Define the styleflag object. | |
StyleFlag flag; | |
// Loop through all the columns in the worksheet and unlock them. | |
for (int i = 0; i <= 255; i++) { | |
style = sheet.getCells().getRows().get(i).getStyle(); | |
style.setLocked(false); | |
flag = new StyleFlag(); | |
flag.setLocked(true); | |
sheet.getCells().getRows().get(i).applyStyle(style, flag); | |
} | |
// Get the first Roww style. | |
style = sheet.getCells().getRows().get(1).getStyle(); | |
// Lock it. | |
style.setLocked(true); | |
// Instantiate the flag. | |
flag = new StyleFlag(); | |
// Set the lock setting. | |
flag.setLocked(true); | |
// Apply the style to the first row. | |
sheet.getCells().getRows().get(1).applyStyle(style, flag); | |
sheet.protect(ProtectionType.ALL); | |
// Save the excel file. | |
wb.save(dataDir + "ProtectRowWorksheet_out.xls", FileFormatType.EXCEL_97_TO_2003); | |
// Print Message | |
System.out.println("Row protected successfully."); |
Çalışma Sayfasında Bir Sütunu Koruma
Aspose.Cells, çalışma sayfasındaki herhangi bir sütunu kolayca kilitlemenizi sağlar. Burada, kullanabilirizApplyStyle() yöntemiKolon çalışma sayfasındaki belirli bir sütuna Stil uygulamak için sınıf. Bu yöntem iki argüman alır: astil nesne veStil Bayrağı Uygulanan biçimlendirme ile ilgili tüm üyeleri içeren yapı.
Aşağıdaki örnek, çalışma sayfasındaki bir sütunun nasıl korunacağını gösterir. Önce çalışma sayfasındaki tüm hücrelerin kilidini açar ve ardından ilk sütunu kilitler. Son olarak, çalışma sayfasını korur. Bir satır/sütun, ayrıca bir dizi Kilitli yöntemi içeren bir Stil API’e sahiptir. StyleFlag yapısını kullanarak satırı / sütunu kilitleyebilir veya kilidini açabilirsiniz.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ProtectColumnWorksheet.class) + "worksheets/"; | |
// Create a new workbook. | |
Workbook wb = new Workbook(); | |
// Create a worksheet object and obtain the first sheet. | |
Worksheet sheet = wb.getWorksheets().get(0); | |
// Define the style object. | |
Style style; | |
// Define the styleflag object. | |
StyleFlag flag; | |
// Loop through all the columns in the worksheet and unlock them. | |
for (int i = 0; i <= 255; i++) { | |
style = sheet.getCells().getColumns().get(i).getStyle(); | |
style.setLocked(false); | |
flag = new StyleFlag(); | |
flag.setLocked(true); | |
sheet.getCells().getColumns().get(i).applyStyle(style, flag); | |
} | |
// Get the first column style. | |
style = sheet.getCells().getColumns().get(0).getStyle(); | |
// Lock it. | |
style.setLocked(true); | |
// Instantiate the flag. | |
flag = new StyleFlag(); | |
// Set the lock setting. | |
flag.setLocked(true); | |
// Apply the style to the first column. | |
sheet.getCells().getColumns().get(0).applyStyle(style, flag); | |
sheet.protect(ProtectionType.ALL); | |
// Save the excel file. | |
wb.save(dataDir + "PColumnWorksheet_out.xls", FileFormatType.EXCEL_97_TO_2003); | |
// Print Message | |
System.out.println("Column protected successfully."); |
Bir Çalışma Sayfasının korumasını kaldırın
Çalışma Sayfalarını Koruma veExcel XP’den bu yana Gelişmiş Koruma Ayarları çalışma sayfalarını korumaya yönelik farklı yaklaşımları tartıştı. Bir geliştiricinin dosyada bazı değişiklikler yapılabilmesi için çalışma zamanında korumalı bir çalışma sayfasındaki korumayı kaldırması gerekirse ne olur? Bu, Aspose.Cells ile kolayca yapılabilir.
Microsoft Excel’i kullanma
Bir çalışma sayfasından korumayı kaldırmak için:
itibarenAraçlar menü, seçKoruma bunu takibenSayfanın korumasını kaldır.
Korumayı Kaldır Sayfasını Seçme
Çalışma sayfası parola korumalı olmadığı sürece koruma kaldırılır. Bu durumda, bir iletişim kutusu parola ister.
Çalışma sayfasının korumasını kaldırmak için parola girme
Aspose.Cells’i kullanma
Bir çalışma sayfası, çağrılarak korumasız bırakılabilir.Çalışma kağıdı sınıf'Korumayı kaldır yöntem. buKorumayı kaldır yöntemi aşağıda açıklanan iki şekilde kullanılabilir.
Basitçe Korunan Bir Çalışma Sayfasının Korumasını Kaldırma
Basitçe korunan bir çalışma sayfası, parola ile korunmayan bir çalışma sayfasıdır. Bu tür çalışma sayfaları, bir parametre geçirmeden unprotect yöntemi çağrılarak korumasızlaştırılabilir.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(UnprotectingSimplyProtectedWorksheet.class) + "worksheets/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
WorksheetCollection worksheets = workbook.getWorksheets(); | |
Worksheet worksheet = worksheets.get(0); | |
Protection protection = worksheet.getProtection(); | |
// The following 3 methods are only for Excel 2000 and earlier formats | |
protection.setAllowEditingContent(false); | |
protection.setAllowEditingObject(false); | |
protection.setAllowEditingScenario(false); | |
// Unprotecting the worksheet | |
worksheet.unprotect(); | |
// Save the excel file. | |
workbook.save(dataDir + "USPWorksheet_out.xls", FileFormatType.EXCEL_97_TO_2003); | |
// Print Message | |
System.out.println("Worksheet unprotected successfully."); |
Parola Korumalı Çalışma Sayfasının Korumasını Kaldırma
Parola korumalı bir çalışma sayfası, parolayla korunan bir çalışma sayfasıdır. Bu tür çalışma sayfaları, parolayı parametre olarak alan Unprotect yönteminin aşırı yüklenmiş bir sürümü çağrılarak korumasız bırakılabilir.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(UnprotectProtectSheet.class) + "worksheets/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
WorksheetCollection worksheets = workbook.getWorksheets(); | |
Worksheet worksheet = worksheets.get(0); | |
// Unprotecting the worksheet | |
worksheet.unprotect("aspose"); | |
// Save the excel file. | |
workbook.save(dataDir + "UnprotectProtectSheet_out.xls", FileFormatType.EXCEL_97_TO_2003); | |
// Print Message | |
System.out.println("Worksheet unprotected successfully."); |
Excel XP’den bu yana Gelişmiş Koruma Ayarları
Çalışma Sayfalarını Koruma Microsoft Excel 97 ve 2000’de bir çalışma sayfasının korunması ele alındı. Ancak Excel 2002 veya XP’nin piyasaya sürülmesinden bu yana, Microsoft birçok gelişmiş koruma ayarı ekledi. Bu koruma ayarları, kullanıcıların şunları yapmasına izin verir veya kısıtlar:
- Satırları veya sütunları silin.
- İçeriği, nesneleri veya senaryoları düzenleyin.
- Hücreleri, satırları veya sütunları biçimlendirin.
- Satırları, sütunları veya köprüleri ekleyin.
- Kilitli veya kilidi açılmış hücreleri seçin.
- Pivot tabloları ve çok daha fazlasını kullanın.
Aspose.Cells, Excel XP ve sonraki sürümleri tarafından sunulan tüm gelişmiş koruma ayarlarını destekler.
Excel XP ve Sonraki Sürümleri Kullanan Gelişmiş Koruma Ayarları
Excel XP’de bulunan koruma ayarlarını görüntülemek için:
- itibarenAraçlar menü, seçKoruma bunu takibenSayfayı Koruyun. Bir iletişim kutusu görüntülenir.
Excel XP’de koruma seçeneklerini gösteren iletişim kutusu
- Çalışma sayfası özelliklerine izin verin veya bunları kısıtlayın ya da bir parola uygulayın.
Aspose.Cells Kullanarak Gelişmiş Koruma Ayarları
Aspose.Cells, tüm gelişmiş koruma ayarlarını destekler.
Aspose.Cells bir sınıf sağlar,Çalışma kitabı , bu bir Microsoft Excel dosyasını temsil eder. Workbook sınıfı, Excel dosyasındaki her çalışma sayfasına erişim sağlayan bir WorksheetCollection koleksiyonu içerir. Bir çalışma sayfası şununla temsil edilir:Çalışma kağıdı sınıf.
Worksheet sınıfı, bu gelişmiş koruma ayarlarını uygulamak için kullanılan Koruma özelliğini sağlar. Koruma özelliği aslında bir nesnesidir.Koruma kısıtlamaları devre dışı bırakmak veya etkinleştirmek için çeşitli Boolean özelliklerini kapsayan sınıf.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AdvancedProtectionSettingsUsingAsposeCells.class) + "worksheets/"; | |
// Instantiating a Workbook object by excel file path | |
Workbook excel = new Workbook(dataDir + "book1.xlsx"); | |
WorksheetCollection worksheets = excel.getWorksheets(); | |
Worksheet worksheet = worksheets.get(0); | |
Protection protection = worksheet.getProtection(); | |
// Restricting users to delete columns of the worksheet | |
protection.setAllowDeletingColumn(false); | |
// Restricting users to delete row of the worksheet | |
protection.setAllowDeletingRow(false); | |
// Restricting users to edit contents of the worksheet | |
protection.setAllowEditingContent(false); | |
// Restricting users to edit objects of the worksheet | |
protection.setAllowEditingObject(false); | |
// Restricting users to edit scenarios of the worksheet | |
protection.setAllowEditingScenario(false); | |
// Restricting users to filter | |
protection.setAllowFiltering(false); | |
// Allowing users to format cells of the worksheet | |
protection.setAllowFormattingCell(true); | |
// Allowing users to format rows of the worksheet | |
protection.setAllowFormattingRow(true); | |
// Allowing users to insert columns in the worksheet | |
protection.setAllowInsertingColumn(true); | |
// Allowing users to insert hyperlinks in the worksheet | |
protection.setAllowInsertingHyperlink(true); | |
// Allowing users to insert rows in the worksheet | |
protection.setAllowInsertingRow(true); | |
// Allowing users to select locked cells of the worksheet | |
protection.setAllowSelectingLockedCell(true); | |
// Allowing users to select unlocked cells of the worksheet | |
protection.setAllowSelectingUnlockedCell(true); | |
// Allowing users to sort | |
protection.setAllowSorting(true); | |
// Allowing users to use pivot tables in the worksheet | |
protection.setAllowUsingPivotTable(true); | |
// Saving the modified Excel file Excel XP format | |
excel.save(dataDir + "APSettingsUsingAsposeCells_out.xls", FileFormatType.EXCEL_97_TO_2003); | |
// Print Message | |
System.out.println("Worksheet protected successfully."); |
Aşağıda küçük bir örnek uygulama var. Bir Excel dosyasını açar ve Excel XP ve sonraki sürümleri tarafından desteklenen gelişmiş koruma ayarlarının çoğunu kullanır.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AdvancedProtection.class) + "worksheets/"; | |
// Instantiating a Workbook object by excel file path | |
Workbook excel = new Workbook(dataDir + "book1.xls"); | |
WorksheetCollection worksheets = excel.getWorksheets(); | |
Worksheet worksheet = worksheets.get(0); | |
Protection protection = worksheet.getProtection(); | |
// Restricting users to delete columns of the worksheet | |
protection.setAllowDeletingColumn(false); | |
// Restricting users to delete row of the worksheet | |
protection.setAllowDeletingRow(false); | |
// Restricting users to edit contents of the worksheet | |
protection.setAllowEditingContent(false); | |
// Restricting users to edit objects of the worksheet | |
protection.setAllowEditingObject(false); | |
// Restricting users to edit scenarios of the worksheet | |
protection.setAllowEditingScenario(false); | |
// Restricting users to filter | |
protection.setAllowFiltering(false); | |
// Allowing users to format cells of the worksheet | |
protection.setAllowFormattingCell(true); | |
// Allowing users to format rows of the worksheet | |
protection.setAllowFormattingRow(true); | |
// Allowing users to insert columns in the worksheet | |
protection.setAllowInsertingColumn(true); | |
// Allowing users to insert hyperlinks in the worksheet | |
protection.setAllowInsertingHyperlink(true); | |
// Allowing users to insert rows in the worksheet | |
protection.setAllowInsertingRow(true); | |
// Allowing users to select locked cells of the worksheet | |
protection.setAllowSelectingLockedCell(true); | |
// Allowing users to select unlocked cells of the worksheet | |
protection.setAllowSelectingUnlockedCell(true); | |
// Allowing users to sort | |
protection.setAllowSorting(true); | |
// Allowing users to use pivot tables in the worksheet | |
protection.setAllowUsingPivotTable(true); | |
// Saving the modified Excel file Excel XP format | |
excel.save(dataDir + "AdvancedProtection_out.xls", FileFormatType.EXCEL_97_TO_2003); | |
// Print Message | |
System.out.println("Worksheet protected successfully."); |
Cell Kilitleme Sorunu
Kullanıcıların hücreleri düzenlemesini kısıtlamak istiyorsanız, herhangi bir koruma ayarı uygulanmadan önce hücreler kilitlenmelidir. Aksi takdirde, çalışma sayfası korumalı olsa bile hücreler düzenlenebilir. Microsoft Excel XP’de hücreler aşağıdaki iletişim kutusu aracılığıyla kilitlenebilir:
Excel XP’de hücreleri kilitlemek için iletişim kutusu
Aspose.Cells API kullanarak da hücreleri kilitlemek mümkündür. Her hücre, ayrıca bir setLocked yöntemi içeren bir Stil API’e sahiptir. Hücreleri kilitlemek veya kilidini açmak için kullanın.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(LockCell.class) + "worksheets/"; | |
// Instantiating a Workbook object by excel file path | |
Workbook excel = new Workbook(dataDir + "Book1.xlsx"); | |
WorksheetCollection worksheets = excel.getWorksheets(); | |
Worksheet worksheet = worksheets.get(0); | |
worksheet.getCells().get("A1").getStyle().setLocked(true); | |
// Saving the modified Excel file Excel XP format | |
excel.save(dataDir + "LockCell_out.xls", FileFormatType.EXCEL_97_TO_2003); | |
// Print Message | |
System.out.println("Cell Locked successfully."); |