org.apache.poi.ss.usermodel.CellStyle.setLocked()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(16.4k)|赞(0)|评价(0)|浏览(472)

本文整理了Java中org.apache.poi.ss.usermodel.CellStyle.setLocked()方法的一些代码示例,展示了CellStyle.setLocked()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CellStyle.setLocked()方法的具体详情如下:
包路径:org.apache.poi.ss.usermodel.CellStyle
类名称:CellStyle
方法名:setLocked

CellStyle.setLocked介绍

[英]set the cell's using this style to be locked
[中]将使用此样式的单元格设置为锁定

代码示例

代码示例来源:origin: alibaba/easyexcel

  1. /**
  2. *
  3. * @param workbook
  4. * @return
  5. */
  6. public static CellStyle buildDefaultCellStyle(Workbook workbook) {
  7. CellStyle newCellStyle = workbook.createCellStyle();
  8. Font font = workbook.createFont();
  9. font.setFontName("宋体");
  10. font.setFontHeightInPoints((short)14);
  11. font.setBold(true);
  12. newCellStyle.setFont(font);
  13. newCellStyle.setWrapText(true);
  14. newCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
  15. newCellStyle.setAlignment(HorizontalAlignment.CENTER);
  16. newCellStyle.setLocked(true);
  17. newCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
  18. newCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
  19. newCellStyle.setBorderBottom(BorderStyle.THIN);
  20. newCellStyle.setBorderLeft(BorderStyle.THIN);
  21. return newCellStyle;
  22. }

代码示例来源:origin: stackoverflow.com

  1. String file = "c:\\poitest.xlsx";
  2. FileOutputStream outputStream = new FileOutputStream(file);
  3. Workbook wb = new XSSFWorkbook();
  4. CellStyle unlockedCellStyle = wb.createCellStyle();
  5. unlockedCellStyle.setLocked(false);
  6. Sheet sheet = wb.createSheet();
  7. sheet.protectSheet("password");
  8. Row row = sheet.createRow(0);
  9. Cell cell = row.createCell(0);
  10. cell.setCellValue("TEST");
  11. cell.setCellStyle(unlockedCellStyle);
  12. wb.write(outputStream);
  13. outputStream.close();

代码示例来源:origin: stackoverflow.com

  1. String file = "c:\\poitest.xlsx";
  2. FileOutputStream outputStream = new FileOutputStream(file);
  3. Workbook wb = new XSSFWorkbook();
  4. CellStyle unlockedCellStyle = wb.createCellStyle();
  5. unlockedCellStyle.setLocked(false);
  6. Sheet sheet = wb.createSheet();
  7. sheet.protectSheet("password");
  8. Row row = sheet.createRow(0);
  9. Cell cell = row.createCell(0);
  10. cell.setCellValue("TEST");
  11. cell.setCellStyle(unlockedCellStyle);
  12. wb.write(outputStream);
  13. outputStream.close();

代码示例来源:origin: org.apache.poi/poi

  1. /**
  2. * Sets the format properties of the given style based on the given map.
  3. *
  4. * @param style cell style
  5. * @param workbook parent workbook
  6. * @param properties map of format properties (String -> Object)
  7. * @see #getFormatProperties(CellStyle)
  8. */
  9. private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
  10. style.setAlignment(getHorizontalAlignment(properties, ALIGNMENT));
  11. style.setVerticalAlignment(getVerticalAlignment(properties, VERTICAL_ALIGNMENT));
  12. style.setBorderBottom(getBorderStyle(properties, BORDER_BOTTOM));
  13. style.setBorderLeft(getBorderStyle(properties, BORDER_LEFT));
  14. style.setBorderRight(getBorderStyle(properties, BORDER_RIGHT));
  15. style.setBorderTop(getBorderStyle(properties, BORDER_TOP));
  16. style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
  17. style.setDataFormat(getShort(properties, DATA_FORMAT));
  18. style.setFillPattern(getFillPattern(properties, FILL_PATTERN));
  19. style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
  20. style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
  21. style.setFont(workbook.getFontAt(getInt(properties, FONT)));
  22. style.setHidden(getBoolean(properties, HIDDEN));
  23. style.setIndention(getShort(properties, INDENTION));
  24. style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
  25. style.setLocked(getBoolean(properties, LOCKED));
  26. style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR));
  27. style.setRotation(getShort(properties, ROTATION));
  28. style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR));
  29. style.setWrapText(getBoolean(properties, WRAP_TEXT));
  30. }

代码示例来源:origin: Vatavuk/excel-io

  1. @Override
  2. public void accept(final CellStyle style) {
  3. style.setLocked(this.value);
  4. }
  5. }

代码示例来源:origin: stackoverflow.com

  1. CellStyle editableStyle = workbook.createCellStyle();
  2. editableStyle.setLocked(false);
  3. for (int i = 0; i < numColumns; i++) {
  4. sheet.setDefaultColumnStyle(i, editableStyle);
  5. }

代码示例来源:origin: stackoverflow.com

  1. CellStyle unlockedCellStyle = wb.createCellStyle();
  2. unlockedCellStyle.setLocked(true); //true or false based on the cell.
  3. cell.setCellStyle(unlockedCellStyle);

代码示例来源:origin: stackoverflow.com

  1. Workbook wb = new XSSFWorkbook();
  2. CellStyle lockedCellStyle = wb.createCellStyle();
  3. lockedCellStyle.setLocked(true);
  4. Sheet sheet = wb.createSheet();
  5. // .... Create rows and cells as needed
  6. // When Writing or reading
  7. Cell cell = getCellsToLockWithAnyMethod();
  8. cell.setCellStyle(lockedCellStyle);

代码示例来源:origin: stackoverflow.com

  1. String file = "C:\\poitest.xlsx";
  2. FileOutputStream outputStream = new FileOutputStream(file);
  3. Workbook wb = new XSSFWorkbook();
  4. CellStyle unlockedCellStyle = wb.createCellStyle();
  5. unlockedCellStyle.setLocked(false);
  6. Sheet sheet = wb.createSheet();
  7. sheet.protectSheet("password");
  8. Row row = sheet.createRow(0);
  9. Cell cell = row.createCell(0);
  10. cell.setCellValue("TEST");
  11. cell.setCellStyle(unlockedCellStyle);
  12. Cell cell2 = row.createCell(1);
  13. cell2.setCellValue("TEST2");
  14. wb.write(outputStream);
  15. outputStream.close();

代码示例来源:origin: stackoverflow.com

  1. HSSFWorkbook wb = new HSSFWorkbook();
  2. HSSFSheet sheet = wb.createSheet("Test");
  3. Row row = sheet.createRow(0);
  4. CellStyle style = wb.createCellStyle();
  5. style.setLocked(true);
  6. cell = row.createCell(0);
  7. cell.setCellStyle(style);
  8. // this is important as locking is pnly activated if sheet is protected
  9. sheet.protectSheet("");

代码示例来源:origin: net.sf.jxls/jxls-core

  1. newStyle.setIndention(style.getIndention());
  2. newStyle.setLeftBorderColor(style.getLeftBorderColor());
  3. newStyle.setLocked(style.getLocked());
  4. newStyle.setRightBorderColor(style.getRightBorderColor());
  5. newStyle.setTopBorderColor(style.getTopBorderColor());

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

  1. /**
  2. * Sets the format properties of the given style based on the given map.
  3. *
  4. * @param style cell style
  5. * @param workbook parent workbook
  6. * @param properties map of format properties (String -> Object)
  7. * @see #getFormatProperties(CellStyle)
  8. */
  9. private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
  10. style.setAlignment(getHorizontalAlignment(properties, ALIGNMENT));
  11. style.setVerticalAlignment(getVerticalAlignment(properties, VERTICAL_ALIGNMENT));
  12. style.setBorderBottom(getBorderStyle(properties, BORDER_BOTTOM));
  13. style.setBorderLeft(getBorderStyle(properties, BORDER_LEFT));
  14. style.setBorderRight(getBorderStyle(properties, BORDER_RIGHT));
  15. style.setBorderTop(getBorderStyle(properties, BORDER_TOP));
  16. style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
  17. style.setDataFormat(getShort(properties, DATA_FORMAT));
  18. style.setFillPattern(getFillPattern(properties, FILL_PATTERN));
  19. style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
  20. style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
  21. style.setFont(workbook.getFontAt(getInt(properties, FONT)));
  22. style.setHidden(getBoolean(properties, HIDDEN));
  23. style.setIndention(getShort(properties, INDENTION));
  24. style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
  25. style.setLocked(getBoolean(properties, LOCKED));
  26. style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR));
  27. style.setRotation(getShort(properties, ROTATION));
  28. style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR));
  29. style.setWrapText(getBoolean(properties, WRAP_TEXT));
  30. }

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

  1. /**
  2. * Sets the format properties of the given style based on the given map.
  3. *
  4. * @param style cell style
  5. * @param workbook parent workbook
  6. * @param properties map of format properties (String -> Object)
  7. * @see #getFormatProperties(CellStyle)
  8. */
  9. private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
  10. style.setAlignment(getShort(properties, ALIGNMENT));
  11. style.setBorderBottom(getShort(properties, BORDER_BOTTOM));
  12. style.setBorderLeft(getShort(properties, BORDER_LEFT));
  13. style.setBorderRight(getShort(properties, BORDER_RIGHT));
  14. style.setBorderTop(getShort(properties, BORDER_TOP));
  15. style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
  16. style.setDataFormat(getShort(properties, DATA_FORMAT));
  17. style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
  18. style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
  19. style.setFillPattern(getShort(properties, FILL_PATTERN));
  20. style.setFont(workbook.getFontAt(getShort(properties, FONT)));
  21. style.setHidden(getBoolean(properties, HIDDEN));
  22. style.setIndention(getShort(properties, INDENTION));
  23. style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
  24. style.setLocked(getBoolean(properties, LOCKED));
  25. style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR));
  26. style.setRotation(getShort(properties, ROTATION));
  27. style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR));
  28. style.setVerticalAlignment(getShort(properties, VERTICAL_ALIGNMENT));
  29. style.setWrapText(getBoolean(properties, WRAP_TEXT));
  30. }

代码示例来源:origin: com.haulmont.thirdparty/poi

  1. /**
  2. * Sets the format properties of the given style based on the given map.
  3. *
  4. * @param style cell style
  5. * @param workbook parent workbook
  6. * @param properties map of format properties (String -> Object)
  7. * @see #getFormatProperties(CellStyle)
  8. */
  9. private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
  10. style.setAlignment(getShort(properties, ALIGNMENT));
  11. style.setBorderBottom(getShort(properties, BORDER_BOTTOM));
  12. style.setBorderLeft(getShort(properties, BORDER_LEFT));
  13. style.setBorderRight(getShort(properties, BORDER_RIGHT));
  14. style.setBorderTop(getShort(properties, BORDER_TOP));
  15. style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
  16. style.setDataFormat(getShort(properties, DATA_FORMAT));
  17. style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
  18. style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
  19. style.setFillPattern(getShort(properties, FILL_PATTERN));
  20. style.setFont(workbook.getFontAt(getShort(properties, FONT)));
  21. style.setHidden(getBoolean(properties, HIDDEN));
  22. style.setIndention(getShort(properties, INDENTION));
  23. style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
  24. style.setLocked(getBoolean(properties, LOCKED));
  25. style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR));
  26. style.setRotation(getShort(properties, ROTATION));
  27. style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR));
  28. style.setVerticalAlignment(getShort(properties, VERTICAL_ALIGNMENT));
  29. style.setWrapText(getBoolean(properties, WRAP_TEXT));
  30. }

代码示例来源:origin: com.eas.platypus/platypus-js-reports

  1. private void copyStyle(Workbook workbook, Cell fromCell, Cell toCell) {
  2. CellStyle toStyle = toCell.getCellStyle();
  3. CellStyle fromStyle = fromCell.getCellStyle();
  4. CellStyle newStyle = workbook.createCellStyle();
  5. newStyle.setAlignment(fromStyle.getAlignment());
  6. newStyle.setBorderBottom(fromStyle.getBorderBottom());
  7. newStyle.setBorderLeft(fromStyle.getBorderLeft());
  8. newStyle.setBorderRight(fromStyle.getBorderRight());
  9. newStyle.setBorderTop(fromStyle.getBorderTop());
  10. newStyle.setBottomBorderColor(fromStyle.getBottomBorderColor());
  11. newStyle.setFillBackgroundColor(fromStyle.getFillBackgroundColor());
  12. newStyle.setFillForegroundColor(fromStyle.getFillForegroundColor());
  13. newStyle.setFillPattern(fromStyle.getFillPattern());
  14. newStyle.setFont(workbook.getFontAt(fromStyle.getFontIndex()));
  15. newStyle.setHidden(fromStyle.getHidden());
  16. newStyle.setIndention(fromStyle.getIndention());
  17. newStyle.setLeftBorderColor(fromStyle.getLeftBorderColor());
  18. newStyle.setLocked(fromStyle.getLocked());
  19. newStyle.setRightBorderColor(fromStyle.getRightBorderColor());
  20. newStyle.setTopBorderColor(fromStyle.getTopBorderColor());
  21. newStyle.setVerticalAlignment(fromStyle.getVerticalAlignment());
  22. newStyle.setWrapText(fromStyle.getWrapText());
  23. newStyle.setDataFormat(toStyle.getDataFormat());
  24. toCell.setCellStyle(newStyle);
  25. }
  26. }

代码示例来源:origin: SheetJS/jxls

  1. newStyle.setIndention(style.getIndention());
  2. newStyle.setLeftBorderColor(style.getLeftBorderColor());
  3. newStyle.setLocked(style.getLocked());
  4. newStyle.setRightBorderColor(style.getRightBorderColor());
  5. newStyle.setTopBorderColor(style.getTopBorderColor());

代码示例来源:origin: org.apache.poi/poi-contrib

  1. /**
  2. * Sets the format properties of the given style based on the given map.
  3. *
  4. * @param style cell style
  5. * @param workbook parent workbook
  6. * @param properties map of format properties (String -> Object)
  7. * @see #getFormatProperties(CellStyle)
  8. */
  9. private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
  10. style.setAlignment(getShort(properties, ALIGNMENT));
  11. style.setBorderBottom(getShort(properties, BORDER_BOTTOM));
  12. style.setBorderLeft(getShort(properties, BORDER_LEFT));
  13. style.setBorderRight(getShort(properties, BORDER_RIGHT));
  14. style.setBorderTop(getShort(properties, BORDER_TOP));
  15. style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
  16. style.setDataFormat(getShort(properties, DATA_FORMAT));
  17. style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
  18. style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
  19. style.setFillPattern(getShort(properties, FILL_PATTERN));
  20. style.setFont(workbook.getFontAt(getShort(properties, FONT)));
  21. style.setHidden(getBoolean(properties, HIDDEN));
  22. style.setIndention(getShort(properties, INDENTION));
  23. style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
  24. style.setLocked(getBoolean(properties, LOCKED));
  25. style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR));
  26. style.setRotation(getShort(properties, ROTATION));
  27. style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR));
  28. style.setVerticalAlignment(getShort(properties, VERTICAL_ALIGNMENT));
  29. style.setWrapText(getBoolean(properties, WRAP_TEXT));
  30. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

  1. /**
  2. * Sets the format properties of the given style based on the given map.
  3. *
  4. * @param style cell style
  5. * @param workbook parent workbook
  6. * @param properties map of format properties (String -> Object)
  7. * @see #getFormatProperties(CellStyle)
  8. */
  9. private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
  10. style.setAlignment(getShort(properties, ALIGNMENT));
  11. style.setBorderBottom(getShort(properties, BORDER_BOTTOM));
  12. style.setBorderLeft(getShort(properties, BORDER_LEFT));
  13. style.setBorderRight(getShort(properties, BORDER_RIGHT));
  14. style.setBorderTop(getShort(properties, BORDER_TOP));
  15. style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
  16. style.setDataFormat(getShort(properties, DATA_FORMAT));
  17. style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
  18. style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
  19. style.setFillPattern(getShort(properties, FILL_PATTERN));
  20. style.setFont(workbook.getFontAt(getShort(properties, FONT)));
  21. style.setHidden(getBoolean(properties, HIDDEN));
  22. style.setIndention(getShort(properties, INDENTION));
  23. style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
  24. style.setLocked(getBoolean(properties, LOCKED));
  25. style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR));
  26. style.setRotation(getShort(properties, ROTATION));
  27. style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR));
  28. style.setVerticalAlignment(getShort(properties, VERTICAL_ALIGNMENT));
  29. style.setWrapText(getBoolean(properties, WRAP_TEXT));
  30. }

代码示例来源:origin: SheetJS/jxls

  1. private void copyStyle(Workbook workbook, org.apache.poi.ss.usermodel.Cell fromCell, org.apache.poi.ss.usermodel.Cell toCell){
  2. CellStyle toStyle = toCell.getCellStyle();
  3. CellStyle fromStyle = fromCell.getCellStyle();
  4. if( fromStyle.getDataFormat() == toStyle.getDataFormat() ){
  5. toCell.setCellStyle( fromStyle );
  6. }else{
  7. CellStyle newStyle = workbook.createCellStyle();
  8. newStyle.setAlignment( toStyle.getAlignment() );
  9. newStyle.setBorderBottom( toStyle.getBorderBottom() );
  10. newStyle.setBorderLeft( toStyle.getBorderLeft() );
  11. newStyle.setBorderRight( toStyle.getBorderRight() );
  12. newStyle.setBorderTop( toStyle.getBorderTop() );
  13. newStyle.setBottomBorderColor( toStyle.getBottomBorderColor() );
  14. newStyle.setDataFormat( toStyle.getDataFormat() );
  15. newStyle.setFillBackgroundColor( fromStyle.getFillBackgroundColor() );
  16. newStyle.setFillForegroundColor( fromStyle.getFillForegroundColor() );
  17. newStyle.setFillPattern( fromStyle.getFillPattern() );
  18. newStyle.setFont( workbook.getFontAt( fromStyle.getFontIndex() ) );
  19. newStyle.setHidden( toStyle.getHidden() );
  20. newStyle.setIndention( toStyle.getIndention() );
  21. newStyle.setLeftBorderColor( toStyle.getLeftBorderColor() );
  22. newStyle.setLocked( toStyle.getLocked() );
  23. newStyle.setRightBorderColor( toStyle.getRightBorderColor() );
  24. newStyle.setTopBorderColor( toStyle.getTopBorderColor() );
  25. newStyle.setVerticalAlignment( toStyle.getVerticalAlignment() );
  26. newStyle.setWrapText( toStyle.getWrapText() );
  27. toCell.setCellStyle( newStyle );
  28. }
  29. }
  30. }

代码示例来源:origin: com.github.nic-luo/rober-office

  1. toStyle.setLocked(fromStyle.getLocked());

相关文章