कोर सेल ऑपरेशन्स के साथ काम करना

अवलोकन

कोर सेल 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 मान

Enum ValueDescription
STRINGputValue(String) द्वारा संग्रहीत पाठ मान
NUMBERputValue(int) या putValue(double) द्वारा संग्रहीत संख्यात्मक मान
BOOLEANputValue(boolean) द्वारा संग्रहीत बूलियन मान
DATE_TIMEputValue(LocalDateTime) द्वारा संग्रहीत तिथि/समय मान
FORMULAsetFormula(String) द्वारा संग्रहीत सूत्र स्ट्रिंग
BLANKखाली सेल — कोई मान सेट नहीं किया गया है

String मान प्राप्त करना

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");
}
 हिन्दी