Core Cell Operations

Java में Core Cell Operations के साथ कैसे काम करें

अवलोकन

के लिए Cell क्लास स्पेडहेट डेटा के संग्रह और पढ़ने के लिए कोर इकाई है. इस गाइड यह टाइप किए गए मूल्य भंडारण, प्रकार की जांच, सूत्र भोजन और श्रृंखला मूल्य पहुंच को कवर करता है।.

टाइप मूल्य संग्रहीत करें

Cell.putValue() 6 प्रकार के जावा को स्वीकार करें: String, int, double, boolean, LocalDateTime,और Object.प्रत्येक कॉल मूल्य को स्टोर करता है और निर्धारित करता CellValueType वापस लौटें cell.getType(). टाइप किए गए अतिरंज का उपयोग करें जो डेटा के अनुरूप है - कॉल putValue(int) एक पूरे को स्टोर करता है जो बिना दस अंक प्राप्त किए घूमता है:

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

try (Workbook workbook = new Workbook()) {
    WorksheetCollection sheets = workbook.getWorksheets();
    Worksheet sheet = sheets.get(0);
    Cell a1 = sheet.getCells().get("A1");
    a1.putValue("Label");        // String
    Cell b1 = sheet.getCells().get("B1");
    b1.putValue(42);             // int
    Cell c1 = sheet.getCells().get("C1");
    c1.putValue(3.14);           // double
    Cell d1 = sheet.getCells().get("D1");
    d1.putValue(true);           // boolean
    workbook.save("typed.xlsx");
}

मूल्य प्रकार की जांच करें

Call cell.getType() प्राप्त करने के लिए CellValueType किसी भी भंडारण मूल्य के लिए enum मूल्य. उपयोग करें cell.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()) {
    WorksheetCollection sheets = workbook.getWorksheets();
    Worksheet sheet = sheets.get(0);
    Cell b1 = sheet.getCells().get("B1");
    b1.putValue(123);
    CellValueType type = b1.getType();
    System.out.println(type);           // NUMBER
    System.out.println(b1.getStringValue());  // "123"
    workbook.save("inspect.xlsx");
}

सूत्रों का संग्रह

Call cell.setFormula() एक मानक Excel सूत्र श्रृंखला के साथ. सेल प्रकार में परिवर्तन CellValueType.FORMULA और सूत्र XLSX फ़ाइल में संग्रहीत किया जाता है; Excel फ़ोल्डर खोलने के बाद परिणाम को फिर से गणना करता है:

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

try (Workbook workbook = new Workbook()) {
    WorksheetCollection sheets = workbook.getWorksheets();
    Worksheet sheet = sheets.get(0);
    Cell b1 = sheet.getCells().get("B1");
    b1.putValue(100.0);
    Cell c1 = sheet.getCells().get("C1");
    c1.setFormula("=B1*1.2");
    workbook.save("formulas.xlsx");
}

यह भी देखें

 हिन्दी