Dosyaları Açmanın Farklı Yolları

Bir Excel Dosyasını Yol Üzerinden Nasıl Açılır

Geliştiriciler, yerel bilgisayarda dosya yolunu belirterek Microsoft Excel dosyasını Workbook sınıf yapıcı kullanarak açabilirler. Yolu sadece bir dize olarak geçirin. Aspose.Cells for Python via .NET otomatik olarak dosya biçimini algılayacaktır.

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!")

Bir Akış Üzerinden Excel Dosyasını Nasıl Açılır

Ayrıca bir akış olarak bir Excel dosyasını açmak da kolaydır. Bunun için dosyayı içeren Akış nesnesini alan oluşturucunun aşırı yüklenmiş bir sürümünü kullanın.

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()

Yalnızca Veri ile Bir Dosyayı Nasıl Açılır

Yalnızca veri ile bir dosyayı açmak için, ilgili sınıfların öznitelik ve seçeneklerini ayarlamak için LoadOptions ve LoadFilter sınıflarını kullanın.

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!")