طرق مختلفة لفتح الملفات

كيفية فتح ملف إكسل عبر مسار

يمكن للمطورين فتح ملف Microsoft Excel باستخدام مساره على الكمبيوتر المحلي بتحديده في مُنشئ Workbook فئة. ببساطة، قم بتمرير المسار كسلسلة نصية. سيقوم Aspose.Cells for Python via .NET باكتشاف نوع تنسيق الملف تلقائيًا.

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Opening through Path
# Creating a Workbook object and opening an Excel file using its file path
workbook1 = Workbook(dataDir + "Book1.xlsx")
print("Workbook opened using path successfully!")

كيفية فتح ملف إكسل عبر تيار

من السهل أيضًا فتح ملف إكسل كتيار. للقيام بذلك، استخدم النسخة المكدسة من المُنشئ التي تأخذ كائن Stream الذي يحتوي على الملف.

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Opening through Stream
# Create a Stream object
fstream = open(dataDir + "Book2.xls", "rb")
# Creating a Workbook object, open the file from a Stream object
# That contains the content of file and it should support seeking
workbook2 = Workbook(fstream)
print("Workbook opened using stream successfully!")
fstream.close()

كيفية فتح ملف بالبيانات فقط

لفتح ملف يحتوي على بيانات فقط، استخدم فئتي LoadOptions و LoadFilter لتعيين السمة ذات الصلة وخيارات الفئتين لقالب الملف الذي سيتم تحميله.

from aspose.cells import LoadDataFilterOptions, LoadFilter, LoadFormat, LoadOptions, Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Load only specific sheets with data and formulas
# Other objects, items etc. would be discarded
# Instantiate LoadOptions specified by the LoadFormat
loadOptions = LoadOptions(LoadFormat.XLSX)
# Set LoadFilter property to load only data & cell formatting
loadOptions.load_filter = LoadFilter(LoadDataFilterOptions.CELL_DATA)
# Create a Workbook object and opening the file from its path
book = Workbook(dataDir + "Book1.xlsx", loadOptions)
print("File data imported successfully!")