Aspose.Cells FOSS के साथ सूत्रों के साथ काम करें

अवलोकन

Aspose.Cells FOSS enables Python developers to work with formulas in spreadsheet files using the Cell वर्ग। यह formula property सेट करने या प्राप्त करने की अनुमति देती है cellहै formula स्ट्रिंग को साधारण पाठ के रूप में। फ़ॉर्मूले XLSX फ़ाइल में verbatim रूप से संग्रहीत होते हैं और फ़ाइल खोलने पर Excel या LibreOffice द्वारा मूल्यांकित किए जाते हैं — लाइब्रेरी स्वयं runtime पर फ़ॉर्मूला परिणामों का मूल्यांकन नहीं करती।.

यह पृष्ठ फ़ॉर्मूले पढ़ने और लिखने को कवर करता है, जिसका उपयोग Cell class.

मुख्य अवधारणाएँ

Aspose.Cells FOSS stores Excel-compatible formulas as plain strings in the XLSX file. When the saved file is opened in Excel or LibreOffice, those applications evaluate the formulas and display computed results. The library does not evaluate formulas at runtime in Python.

Cell Formula स्टोरेज

यह Cell class अपने में formulas संग्रहीत करता है formula property, जो formula strings को स्वीकार करता है और लौटाता है (जैसे,., =A1+B1). यह data_type property यह दर्शाता है कि सेल में फ़ॉर्मूला, संख्या, स्ट्रिंग या त्रुटि है।.

महत्वपूर्ण: worksheet.calculate_formula() एक संगतता स्टब है और फ़ॉर्मूले का मूल्यांकन नहीं करता। फ़ॉर्मूला मूल्यांकन Excel या LibreOffice में तब होता है जब XLSX फ़ाइल खोली जाती है।.

कार्यान्वयन

Aspose.Cells FOSS enables formula handling in Python via the Cell क्लास। डेवलपर्स फ़ॉर्मूले सेट और प्राप्त कर सकते हैं उपयोग करके the formula संपत्ति.

एक फ़ॉर्मूला सेट करें Cell

इसे उपयोग करें formula एक सेल को फ़ॉर्मूला स्ट्रिंग असाइन करने के लिए प्रॉपर्टी। फ़ॉर्मूला को जैसा है वैसा ही संग्रहीत किया जाता है और फ़ाइल खोलने पर Excel या LibreOffice द्वारा मूल्यांकन किया जाएगा।.

from aspose.cells_foss import Workbook

workbook = Workbook()
worksheet = workbook.worksheets[0]
cell = worksheet.cells.get_cell_by_name("A1")
cell.formula = "=10+20"

एक फ़ॉर्मूला पढ़ें Cell

प्राप्त करें formula string का उपयोग करके formula की प्रॉपर्टी Cell instance। यह raw को लौटाता है formula expression जैसा कि उपयोगकर्ता द्वारा दर्ज किया गया है।.

formula = cell.formula
print(f"Formula: {formula}")

कोड उदाहरण

निम्न उदाहरण एक फ़ॉर्मूला स्ट्रिंग को एक सेल में लिखता है और वर्कबुक को सहेजता है। फ़ॉर्मूला को Excel या LibreOffice द्वारा फ़ाइल खोलने पर मूल्यांकित किया जाएगा।.

from aspose.cells_foss import Workbook

# Create a new workbook and access the first worksheet
workbook = Workbook()
worksheet = workbook.worksheets[0]

# Set a value in A1 and a SUM formula in A2
worksheet.cells.get_cell_by_name('A1').value = 42
worksheet.cells.get_cell_by_name('A2').formula = '=SUM(A1, 10)'

# Save — Excel will compute =SUM(A1, 10) = 52 when it opens the file
workbook.save('formulas.xlsx')
print('Saved formulas.xlsx')

See Also

 हिन्दी