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

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

本文整理了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

/**
 *
 * @param workbook
 * @return
 */
public static CellStyle buildDefaultCellStyle(Workbook workbook) {
  CellStyle newCellStyle = workbook.createCellStyle();
  Font font = workbook.createFont();
  font.setFontName("宋体");
  font.setFontHeightInPoints((short)14);
  font.setBold(true);
  newCellStyle.setFont(font);
  newCellStyle.setWrapText(true);
  newCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
  newCellStyle.setAlignment(HorizontalAlignment.CENTER);
  newCellStyle.setLocked(true);
  newCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
  newCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
  newCellStyle.setBorderBottom(BorderStyle.THIN);
  newCellStyle.setBorderLeft(BorderStyle.THIN);
  return newCellStyle;
}

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

String file = "c:\\poitest.xlsx";
FileOutputStream outputStream = new FileOutputStream(file);
Workbook wb = new XSSFWorkbook();

CellStyle unlockedCellStyle = wb.createCellStyle();
unlockedCellStyle.setLocked(false);

Sheet sheet = wb.createSheet();
sheet.protectSheet("password");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("TEST");
cell.setCellStyle(unlockedCellStyle);

wb.write(outputStream);
outputStream.close();

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

String file = "c:\\poitest.xlsx";
FileOutputStream outputStream = new FileOutputStream(file);
Workbook wb = new XSSFWorkbook();

CellStyle unlockedCellStyle = wb.createCellStyle();
unlockedCellStyle.setLocked(false);

Sheet sheet = wb.createSheet();
sheet.protectSheet("password");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("TEST");
cell.setCellStyle(unlockedCellStyle);

wb.write(outputStream);
outputStream.close();

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

/**
 * Sets the format properties of the given style based on the given map.
 *
 * @param style cell style
 * @param workbook parent workbook
 * @param properties map of format properties (String -> Object)
 * @see #getFormatProperties(CellStyle)
 */
private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
  style.setAlignment(getHorizontalAlignment(properties, ALIGNMENT));
  style.setVerticalAlignment(getVerticalAlignment(properties, VERTICAL_ALIGNMENT));
  style.setBorderBottom(getBorderStyle(properties, BORDER_BOTTOM));
  style.setBorderLeft(getBorderStyle(properties, BORDER_LEFT));
  style.setBorderRight(getBorderStyle(properties, BORDER_RIGHT));
  style.setBorderTop(getBorderStyle(properties, BORDER_TOP));
  style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
  style.setDataFormat(getShort(properties, DATA_FORMAT));
  style.setFillPattern(getFillPattern(properties, FILL_PATTERN));
  style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
  style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
  style.setFont(workbook.getFontAt(getInt(properties, FONT)));
  style.setHidden(getBoolean(properties, HIDDEN));
  style.setIndention(getShort(properties, INDENTION));
  style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
  style.setLocked(getBoolean(properties, LOCKED));
  style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR));
  style.setRotation(getShort(properties, ROTATION));
  style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR));
  style.setWrapText(getBoolean(properties, WRAP_TEXT));
}

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

@Override
  public void accept(final CellStyle style) {
    style.setLocked(this.value);
  }
}

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

CellStyle editableStyle = workbook.createCellStyle();
editableStyle.setLocked(false);

for (int i = 0; i < numColumns; i++) {
  sheet.setDefaultColumnStyle(i, editableStyle);
}

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

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

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

Workbook wb = new XSSFWorkbook();

CellStyle lockedCellStyle = wb.createCellStyle();
lockedCellStyle.setLocked(true);

Sheet sheet = wb.createSheet();
// .... Create rows and cells as needed

// When Writing or reading
Cell cell = getCellsToLockWithAnyMethod();
cell.setCellStyle(lockedCellStyle);

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

String file = "C:\\poitest.xlsx";
   FileOutputStream outputStream = new FileOutputStream(file);
   Workbook wb = new XSSFWorkbook();
   CellStyle unlockedCellStyle = wb.createCellStyle();
   unlockedCellStyle.setLocked(false);
   Sheet sheet = wb.createSheet();
   sheet.protectSheet("password");
   Row row = sheet.createRow(0);
   Cell cell = row.createCell(0);
   cell.setCellValue("TEST");
   cell.setCellStyle(unlockedCellStyle);
   Cell cell2 = row.createCell(1);
   cell2.setCellValue("TEST2");
   wb.write(outputStream);
   outputStream.close();

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

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Test");

Row row = sheet.createRow(0);

CellStyle style = wb.createCellStyle();
style.setLocked(true);
cell = row.createCell(0);
cell.setCellStyle(style);

// this is important as locking is pnly activated if sheet is protected
sheet.protectSheet("");

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

newStyle.setIndention(style.getIndention());
newStyle.setLeftBorderColor(style.getLeftBorderColor());
newStyle.setLocked(style.getLocked());
newStyle.setRightBorderColor(style.getRightBorderColor());
newStyle.setTopBorderColor(style.getTopBorderColor());

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

/**
 * Sets the format properties of the given style based on the given map.
 *
 * @param style cell style
 * @param workbook parent workbook
 * @param properties map of format properties (String -> Object)
 * @see #getFormatProperties(CellStyle)
 */
private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
  style.setAlignment(getHorizontalAlignment(properties, ALIGNMENT));
  style.setVerticalAlignment(getVerticalAlignment(properties, VERTICAL_ALIGNMENT));
  style.setBorderBottom(getBorderStyle(properties, BORDER_BOTTOM));
  style.setBorderLeft(getBorderStyle(properties, BORDER_LEFT));
  style.setBorderRight(getBorderStyle(properties, BORDER_RIGHT));
  style.setBorderTop(getBorderStyle(properties, BORDER_TOP));
  style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
  style.setDataFormat(getShort(properties, DATA_FORMAT));
  style.setFillPattern(getFillPattern(properties, FILL_PATTERN));
  style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
  style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
  style.setFont(workbook.getFontAt(getInt(properties, FONT)));
  style.setHidden(getBoolean(properties, HIDDEN));
  style.setIndention(getShort(properties, INDENTION));
  style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
  style.setLocked(getBoolean(properties, LOCKED));
  style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR));
  style.setRotation(getShort(properties, ROTATION));
  style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR));
  style.setWrapText(getBoolean(properties, WRAP_TEXT));
}

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

/**
 * Sets the format properties of the given style based on the given map.
 *
 * @param style cell style
 * @param workbook parent workbook
 * @param properties map of format properties (String -> Object)
 * @see #getFormatProperties(CellStyle)
 */
private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
  style.setAlignment(getShort(properties, ALIGNMENT));
  style.setBorderBottom(getShort(properties, BORDER_BOTTOM));
  style.setBorderLeft(getShort(properties, BORDER_LEFT));
  style.setBorderRight(getShort(properties, BORDER_RIGHT));
  style.setBorderTop(getShort(properties, BORDER_TOP));
  style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
  style.setDataFormat(getShort(properties, DATA_FORMAT));
  style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
  style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
  style.setFillPattern(getShort(properties, FILL_PATTERN));
  style.setFont(workbook.getFontAt(getShort(properties, FONT)));
  style.setHidden(getBoolean(properties, HIDDEN));
  style.setIndention(getShort(properties, INDENTION));
  style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
  style.setLocked(getBoolean(properties, LOCKED));
  style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR));
  style.setRotation(getShort(properties, ROTATION));
  style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR));
  style.setVerticalAlignment(getShort(properties, VERTICAL_ALIGNMENT));
  style.setWrapText(getBoolean(properties, WRAP_TEXT));
}

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

/**
 * Sets the format properties of the given style based on the given map.
 *
 * @param style cell style
 * @param workbook parent workbook
 * @param properties map of format properties (String -> Object)
 * @see #getFormatProperties(CellStyle)
 */
private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
  style.setAlignment(getShort(properties, ALIGNMENT));
  style.setBorderBottom(getShort(properties, BORDER_BOTTOM));
  style.setBorderLeft(getShort(properties, BORDER_LEFT));
  style.setBorderRight(getShort(properties, BORDER_RIGHT));
  style.setBorderTop(getShort(properties, BORDER_TOP));
  style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
  style.setDataFormat(getShort(properties, DATA_FORMAT));
  style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
  style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
  style.setFillPattern(getShort(properties, FILL_PATTERN));
  style.setFont(workbook.getFontAt(getShort(properties, FONT)));
  style.setHidden(getBoolean(properties, HIDDEN));
  style.setIndention(getShort(properties, INDENTION));
  style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
  style.setLocked(getBoolean(properties, LOCKED));
  style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR));
  style.setRotation(getShort(properties, ROTATION));
  style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR));
  style.setVerticalAlignment(getShort(properties, VERTICAL_ALIGNMENT));
  style.setWrapText(getBoolean(properties, WRAP_TEXT));
}

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

private void copyStyle(Workbook workbook, Cell fromCell, Cell toCell) {
    CellStyle toStyle = toCell.getCellStyle();
    CellStyle fromStyle = fromCell.getCellStyle();
    CellStyle newStyle = workbook.createCellStyle();

    newStyle.setAlignment(fromStyle.getAlignment());
    newStyle.setBorderBottom(fromStyle.getBorderBottom());
    newStyle.setBorderLeft(fromStyle.getBorderLeft());
    newStyle.setBorderRight(fromStyle.getBorderRight());
    newStyle.setBorderTop(fromStyle.getBorderTop());
    newStyle.setBottomBorderColor(fromStyle.getBottomBorderColor());

    newStyle.setFillBackgroundColor(fromStyle.getFillBackgroundColor());
    newStyle.setFillForegroundColor(fromStyle.getFillForegroundColor());
    newStyle.setFillPattern(fromStyle.getFillPattern());
    newStyle.setFont(workbook.getFontAt(fromStyle.getFontIndex()));
    newStyle.setHidden(fromStyle.getHidden());
    newStyle.setIndention(fromStyle.getIndention());
    newStyle.setLeftBorderColor(fromStyle.getLeftBorderColor());
    newStyle.setLocked(fromStyle.getLocked());
    newStyle.setRightBorderColor(fromStyle.getRightBorderColor());
    newStyle.setTopBorderColor(fromStyle.getTopBorderColor());
    newStyle.setVerticalAlignment(fromStyle.getVerticalAlignment());
    newStyle.setWrapText(fromStyle.getWrapText());
    newStyle.setDataFormat(toStyle.getDataFormat());
    toCell.setCellStyle(newStyle);
  }
}

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

newStyle.setIndention(style.getIndention());
newStyle.setLeftBorderColor(style.getLeftBorderColor());
newStyle.setLocked(style.getLocked());
newStyle.setRightBorderColor(style.getRightBorderColor());
newStyle.setTopBorderColor(style.getTopBorderColor());

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

/**
 * Sets the format properties of the given style based on the given map.
 *
 * @param style cell style
 * @param workbook parent workbook
 * @param properties map of format properties (String -> Object)
 * @see #getFormatProperties(CellStyle)
 */
private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
  style.setAlignment(getShort(properties, ALIGNMENT));
  style.setBorderBottom(getShort(properties, BORDER_BOTTOM));
  style.setBorderLeft(getShort(properties, BORDER_LEFT));
  style.setBorderRight(getShort(properties, BORDER_RIGHT));
  style.setBorderTop(getShort(properties, BORDER_TOP));
  style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
  style.setDataFormat(getShort(properties, DATA_FORMAT));
  style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
  style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
  style.setFillPattern(getShort(properties, FILL_PATTERN));
  style.setFont(workbook.getFontAt(getShort(properties, FONT)));
  style.setHidden(getBoolean(properties, HIDDEN));
  style.setIndention(getShort(properties, INDENTION));
  style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
  style.setLocked(getBoolean(properties, LOCKED));
  style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR));
  style.setRotation(getShort(properties, ROTATION));
  style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR));
  style.setVerticalAlignment(getShort(properties, VERTICAL_ALIGNMENT));
  style.setWrapText(getBoolean(properties, WRAP_TEXT));
}

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

/**
 * Sets the format properties of the given style based on the given map.
 *
 * @param style cell style
 * @param workbook parent workbook
 * @param properties map of format properties (String -> Object)
 * @see #getFormatProperties(CellStyle)
 */
private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
  style.setAlignment(getShort(properties, ALIGNMENT));
  style.setBorderBottom(getShort(properties, BORDER_BOTTOM));
  style.setBorderLeft(getShort(properties, BORDER_LEFT));
  style.setBorderRight(getShort(properties, BORDER_RIGHT));
  style.setBorderTop(getShort(properties, BORDER_TOP));
  style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
  style.setDataFormat(getShort(properties, DATA_FORMAT));
  style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
  style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
  style.setFillPattern(getShort(properties, FILL_PATTERN));
  style.setFont(workbook.getFontAt(getShort(properties, FONT)));
  style.setHidden(getBoolean(properties, HIDDEN));
  style.setIndention(getShort(properties, INDENTION));
  style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
  style.setLocked(getBoolean(properties, LOCKED));
  style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR));
  style.setRotation(getShort(properties, ROTATION));
  style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR));
  style.setVerticalAlignment(getShort(properties, VERTICAL_ALIGNMENT));
  style.setWrapText(getBoolean(properties, WRAP_TEXT));
}

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

private void copyStyle(Workbook workbook, org.apache.poi.ss.usermodel.Cell fromCell, org.apache.poi.ss.usermodel.Cell toCell){
    CellStyle toStyle = toCell.getCellStyle();
    CellStyle fromStyle = fromCell.getCellStyle();
    if( fromStyle.getDataFormat() == toStyle.getDataFormat() ){
      toCell.setCellStyle( fromStyle );
    }else{
      CellStyle newStyle = workbook.createCellStyle();
      newStyle.setAlignment( toStyle.getAlignment() );
      newStyle.setBorderBottom( toStyle.getBorderBottom() );
      newStyle.setBorderLeft( toStyle.getBorderLeft() );
      newStyle.setBorderRight( toStyle.getBorderRight() );
      newStyle.setBorderTop( toStyle.getBorderTop() );
      newStyle.setBottomBorderColor( toStyle.getBottomBorderColor() );
      newStyle.setDataFormat( toStyle.getDataFormat() );
      newStyle.setFillBackgroundColor( fromStyle.getFillBackgroundColor() );
      newStyle.setFillForegroundColor( fromStyle.getFillForegroundColor() );
      newStyle.setFillPattern( fromStyle.getFillPattern() );
      newStyle.setFont( workbook.getFontAt( fromStyle.getFontIndex() ) );
      newStyle.setHidden( toStyle.getHidden() );
      newStyle.setIndention( toStyle.getIndention() );
      newStyle.setLeftBorderColor( toStyle.getLeftBorderColor() );
      newStyle.setLocked( toStyle.getLocked() );
      newStyle.setRightBorderColor( toStyle.getRightBorderColor() );
      newStyle.setTopBorderColor( toStyle.getTopBorderColor() );
      newStyle.setVerticalAlignment( toStyle.getVerticalAlignment() );
      newStyle.setWrapText( toStyle.getWrapText() );
      toCell.setCellStyle( newStyle );
    }
  }
}

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

toStyle.setLocked(fromStyle.getLocked());

相关文章

微信公众号

最新文章

更多