public static void main(String[] args) throws Exception { // The path to the documents directory. String dataDir = Utils.getDataDir(ProtectingSpecificColumnInWorksheet.class); // 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); // Save the excel file. wb.save(dataDir + "lockedcolumn.out.xls", FileFormatType.EXCEL_97_TO_2003); // Print Message System.out.println("Column protected successfully."); }
public static void main(String[] args) throws Exception { // The path to the documents directory. String dataDir = Utils.getSharedDataDir(WrapTextinCell.class) + "articles/"; // Create Workbook Object Workbook wb = new Workbook(); // Open first Worksheet in the workbook Worksheet ws = wb.getWorksheets().get(0); // Get Worksheet Cells Collection Cells cell = ws.getCells(); // Increase the width of First Column Width cell.setColumnWidth(0, 35); // Increase the height of first row cell.setRowHeight(0, 65); // Add Text to the First Cell cell.get(0, 0) .setValue("I am using the latest version of Aspose.Cells to test this functionality"); // Get Cell's Style Style style = cell.get(0, 0).getStyle(); // Set Text Wrap property to true style.setTextWrapped(true); // Set Cell's Style cell.get(0, 0).setStyle(style); // Save Excel File wb.save(dataDir + "WrapTextinCell_out.xls"); }