Working with Core Cell Operations

핵심 셀 작업 사용하기

개요

핵심 셀 API는 형식화된 값, 수식 저장, CellValueType를 통한 값 유형 검사, 그리고 getStringValue()를 통한 통일된 문자열 표현을 지원합니다.

형식화된 값 저장

import com.aspose.cells_foss.Cell;
import com.aspose.cells_foss.CellValueType;
import com.aspose.cells_foss.Workbook;
import com.aspose.cells_foss.Worksheet;

try (Workbook workbook = new Workbook()) {
    Worksheet sheet = workbook.getWorksheets().get(0);

    Cell a1 = sheet.getCells().get("A1");
    a1.putValue("Revenue");

    Cell b1 = sheet.getCells().get("B1");
    b1.putValue(42500.75);

    Cell c1 = sheet.getCells().get("C1");
    c1.putValue(true);

    Cell d1 = sheet.getCells().get("D1");
    d1.setFormula("=B1*1.2");

    // Type inspection
    System.out.println(a1.getType());  // STRING
    System.out.println(b1.getType());  // NUMBER
    System.out.println(c1.getType());  // BOOLEAN
    System.out.println(d1.getType());  // FORMULA

    workbook.save("typed.xlsx");
}

CellValueType 열거형 값

Enum ValueDescription
STRINGputValue(String)에 의해 저장된 텍스트 값
NUMBERputValue(int) 또는 putValue(double)에 의해 저장된 숫자 값
BOOLEANputValue(boolean)에 의해 저장된 불리언 값
DATE_TIMEputValue(LocalDateTime)에 의해 저장된 날짜/시간 값
FORMULAsetFormula(String)에 의해 저장된 수식 문자열
BLANK빈 셀 — 값이 설정되지 않음

문자열 값 가져오기

cell.getStringValue()은 로케일에 독립적인 문자열을 반환하며, 기본값 유형에 관계없이 표시 또는 다운스트림 처리에 적합합니다:

import com.aspose.cells_foss.Cell;
import com.aspose.cells_foss.Workbook;
import com.aspose.cells_foss.Worksheet;

try (Workbook workbook = new Workbook()) {
    Worksheet sheet = workbook.getWorksheets().get(0);
    Cell b1 = sheet.getCells().get("B1");
    b1.putValue(123);
    System.out.println(b1.getStringValue());  // "123" — no decimal point
    workbook.save("string-values.xlsx");
}

수식 저장소

import com.aspose.cells_foss.Cell;
import com.aspose.cells_foss.CellValueType;
import com.aspose.cells_foss.Workbook;
import com.aspose.cells_foss.Worksheet;

try (Workbook workbook = new Workbook()) {
    Worksheet sheet = workbook.getWorksheets().get(0);
    Cell b1 = sheet.getCells().get("B1");
    b1.putValue(100.0);
    Cell c1 = sheet.getCells().get("C1");
    c1.setFormula("=B1*1.2");
    System.out.println(c1.getType() == CellValueType.FORMULA);  // true
    workbook.save("formulas.xlsx");
}
 한국어