Farklı Biçimlerdeki Dosyaları Açma

Excel Dosyalarını Açmanın Basit Yolları

Yoldan Açma

Dosya yolunu kullanarak bir Microsoft Excel dosyasını açmak için, örneğini oluştururken dosyanın yolunu bir parametre olarak iletin.**Çalışma Kitabı**sınıf. Aşağıdaki örnek kod, dosya yolunu kullanarak bir Excel dosyasını açmayı gösterir.

Örnek vermek

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(OpeningFilesThroughPath.class) + "files/";
// Opening from path.
// Creating an Workbook object with an Excel file path
Workbook workbook1 = new Workbook(dataDir + "Book1.xlsx");
// Print message
System.out.println("Workbook opened using path successfully.");

Akış yoluyla açma

Bazen açmak istediğiniz Excel dosyası bir akış olarak saklanır. Bu durumda, dosya yolunu kullanarak bir dosyayı açmaya benzer şekilde, akışı başlatırken akışı bir parametre olarak iletin.Çalışma Kitabı sınıf. Aşağıdaki örnek kod, akış kullanılarak bir Excel dosyasının açılmasını gösterir.

Örnek vermek

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(OpeningFilesThroughStream.class) + "loading_saving/";
// Opening workbook from stream
// Create a Stream object
FileInputStream fstream = new FileInputStream(dataDir + "Book2.xls");
// Creating an Workbook object with the stream object
Workbook workbook2 = new Workbook(fstream);
fstream.close();
// Print message
System.out.println("Workbook opened using stream successfully.");

Farklı Microsoft Excel Sürümlerinin Dosyalarını Açma

kullanıcı kullanabilir**LoadOptions** kullanarak Excel dosyasının biçimini belirtmek için sınıf**LoadFormat**numaralandırma.

bu**LoadFormat**numaralandırma, bazıları aşağıda verilen önceden tanımlanmış birçok dosya formatını içerir.

Biçim Türleri Açıklama
Csv CSV dosyasını temsil eder
Excel97To2003 Bir Excel 97 - 2003 dosyasını temsil eder
Xlsx Bir Excel 2007/2010/2013/2016/2019 ve Office 365 XLSX dosyasını temsil eder
Xlsm Bir Excel 2007/2010/2013/2016/2019 ve Office 365 XLSM dosyasını temsil eder
Xltx Bir Excel 2007/2010/2013/2016/2019 ve Office 365 şablonu XLTX dosyasını temsil eder
Xltm Bir Excel 2007/2010/2013/2016/2019 ve Office 365 makro özellikli XLTM dosyasını temsil eder
Xlsb Bir Excel 2007/2010/2013/2016/2019 ve Office 365 ikili XLSB dosyasını temsil eder
SpreadsheetML SpreadsheetML dosyasını temsil eder
Tsv Sekmeyle ayrılmış değerler dosyasını temsil eder
TabDelimited Sekmeyle Ayrılmış bir metin dosyasını temsil eder
Oranlar Bir ODS dosyasını temsil eder
html Bir HTML dosyasını temsil eder
Mhtml Bir MHTML dosyasını temsil eder

Microsoft Excel 95/5.0 Dosyalarını Açma

Microsoft Excel 95 dosyalarını açmak için**Çalışma Kitabı**şablon dosyasının yolu veya akışı ile örnek. Kodu test etmek için örnek dosya aşağıdaki bağlantıdan indirilebilir:

Excel95_5.0.xls

Örnek vermek

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Opening Microsoft Excel 97 Files
// Creating an EXCEL_97_TO_2003 LoadOptions object
// Creating an Workbook object with excel 97 file path and the
// loadOptions object
new Workbook(srcDir + "Excel95_5.0.xls");

Microsoft Excel 97 veya sonraki sürümlerini açma XLS Dosyaları

XLS Microsoft Excel XLS 97 veya sonraki sürümlerin XLS dosyalarını açmak için,Çalışma Kitabışablon dosyasının yolu veya akışı ile örnek. VeyaLoadOptions yöntemini seçin ve**EXCEL_97_TO_2003** içindeki değer**LoadFormat**numaralandırma.

Örnek vermek

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(OpeningMicrosoftExcel972003Files.class) + "loading_saving/";
// Opening Microsoft Excel 97 Files
// Createing and EXCEL_97_TO_2003 LoadOptions object
LoadOptions loadOptions1 = new LoadOptions(LoadFormat.EXCEL_97_TO_2003);
// Creating an Workbook object with excel 97 file path and the
// loadOptions object
Workbook workbook3 = new Workbook(dataDir + "Book_Excel97_2003.xls", loadOptions1);
// Print message
System.out.println("Excel 97 Workbook opened successfully.");

Microsoft Excel 2007 veya sonraki sürümlerini açma XLSX Dosyaları

Microsoft Excel 2007 veya sonraki sürümlerin XLSX dosyalarını açmak için**Çalışma Kitabı**şablon dosyasının yolu veya akışı ile örnek. Veya**LoadOptions** sınıfı seçin ve**XLSX** içindeki değer**LoadFormat**numaralandırma.

Örnek vermek

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(OpeningMicrosoftExcel2007XlsxFiles.class) + "loading_saving/";
// Opening Microsoft Excel 2007 XLSX Files. Createing and XLSX LoadOptions object
LoadOptions loadOptions2 = new LoadOptions(LoadFormat.XLSX);
// Creating an Workbook object with 2007 xlsx file path and the loadOptions object
Workbook workbook4 = new Workbook(dataDir + "Book_Excel2007.xlsx", loadOptions2);
// Print message
System.out.println("Excel 2007 Workbook opened successfully.");

Farklı Biçimlerdeki Dosyaları Açma

Aspose.Cells, geliştiricilerin SpreadsheetML, CSV, Sekmeyle Ayrılmış dosyalar gibi farklı biçimlerdeki elektronik tablo dosyalarını açmasına olanak tanır. Bu tür dosyaları açmak için geliştiriciler, farklı Microsoft Excel sürümlerindeki dosyaları açarken kullandıkları metodolojinin aynısını kullanabilir.

SpreadsheetML Dosyalarını Açma

SpreadsheetML dosyaları, elektronik tablonuzla ilgili biçimlendirme, formüller vb. tüm bilgileri içeren XML temsilleridir. Microsoft Excel XP’den beri, Microsoft Excel’e elektronik tablolarınızı SpreadsheetML dosyalarına aktaran bir XML dışa aktarma seçeneği eklenmiştir.

SpreadsheetML dosyalarını açmak için**LoadOptions** sınıfı seçin ve**SPREADSHEET_ML** içindeki değer**LoadFormat**numaralandırma.

Örnek vermek

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(OpeningSpreadsheetMLFiles.class) + "loading_saving/";
// Opening SpreadsheetML Files
// Creating and EXCEL_2003_XML LoadOptions object
LoadOptions loadOptions3 = new LoadOptions(LoadFormat.SPREADSHEET_ML);
// Creating an Workbook object with SpreadsheetML file path and the
// loadOptions object
Workbook workbook5 = new Workbook(dataDir + "Book3.xml", loadOptions3);
// Print message
System.out.println("SpreadSheetML format workbook has been opened successfully.");

CSV Dosyalarını Açma

Virgülle Ayrılmış Değerler (CSV) dosyaları, değerleri sınırlanmış veya virgülle ayrılmış kayıtlar içerir. CSV dosyalarında veriler, virgül karakteriyle ayrılan ve çift tırnak karakteriyle alıntılanan alanlara sahip tablo biçiminde saklanır. Bir alanın değeri bir çift tırnak karakteri içeriyorsa, bir çift çift tırnak karakteri ile çıkış yapılır. Elektronik tablo verilerinizi bir CSV dosyasına aktarmak için Microsoft Excel’i de kullanabilirsiniz.

CSV dosyalarını açmak için**LoadOptions** sınıfı seçin ve**CSV** değer, önceden tanımlanmış**LoadFormat**numaralandırma.

Örnek vermek

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(OpeningCSVFiles.class) + "loading_saving/";
// Opening CSV Files
// Creating and CSV LoadOptions object
LoadOptions loadOptions4 = new LoadOptions(LoadFormat.CSV);
// Creating an Workbook object with CSV file path and the loadOptions
// object
Workbook workbook6 = new Workbook(dataDir + "Book_CSV.csv", loadOptions4);
// Print message
System.out.println("CSV format workbook has been opened successfully.");

CSV dosyalarının açılması ve geçersiz karakterlerin değiştirilmesi

Excel’de özel karakterler içeren CSV dosyası açıldığında karakterler otomatik olarak değiştirilir. Aynısı, aşağıda verilen kod örneğinde gösterilen Aspose.Cells API tarafından yapılır.

Örnek vermek

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Source directory
String dataDir = Utils.getSharedDataDir(OpeningCSVFilesAndReplacingInvalidCharacters.class) + "LoadingSavingConvertingAndManaging/";
LoadOptions loadOptions = new LoadOptions(LoadFormat.CSV);
//Load CSV file
Workbook workbook = new Workbook(dataDir + "[20180220142533][ASPOSE_CELLS_TEST].csv", loadOptions);
System.out.println(workbook.getWorksheets().get(0).getName()); // (20180220142533)(ASPOSE_CELLS_T
System.out.println(workbook.getWorksheets().get(0).getName().length()); // 31
System.out.println("CSV file opened successfully!");

Tercih edilen ayrıştırıcıyı kullanarak CSV dosyasını açma

Bu, CSV dosyalarını açmak için varsayılan ayrıştırıcı ayarlarını kullanmak için her zaman gerekli değildir. Bazen CSV dosyasının içe aktarılması beklenen çıktıyı oluşturmaz, örneğin tarih biçimi beklendiği gibi değildir veya boş alanlar farklı şekilde işlenir. Bu amaç için**TxtLoadOptions.PreferredParsers**gereksinime göre farklı veri türlerini ayrıştırmak için kendi tercih edilen ayrıştırıcıyı sağlamak için kullanılabilir. Aşağıdaki örnek kod, tercih edilen ayrıştırıcının kullanımını gösterir.

Bu özelliği test etmek için örnek kaynak dosya ve çıktı dosyaları aşağıdaki bağlantılardan indirilebilir.

samplePreferredParser.csv

outputsamplePreferredParser.xlsx

Örnek vermek

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
class TextParser implements ICustomParser
{
@Override
public Object parseObject(String s) {
return s;
}
@Override
public String getFormat() {
return "";
}
}
class DateParser implements ICustomParser {
@Override
public Object parseObject(String s) {
Date myDate = null;
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
try {
myDate = formatter.parse(s);
} catch (ParseException e) {
e.printStackTrace();
}
return myDate;
}
@Override
public String getFormat() {
return "dd/MM/yyyy";
}
}
public class OpeningCSVFilesWithPreferredParser {
//Source directory
private static String sourceDir = Utils.Get_SourceDirectory();
private static String outputDir = Utils.Get_OutputDirectory();
public static void main(String[] args) throws Exception {
// Initialize Text File's Load options
TxtLoadOptions oTxtLoadOptions = new TxtLoadOptions(LoadFormat.CSV);
// Specify the separatot character
oTxtLoadOptions.setSeparator(',');
// Specify the encoding scheme
oTxtLoadOptions.setEncoding(Encoding.getUTF8());
// Set the flag to true for converting datetime data
oTxtLoadOptions.setConvertDateTimeData(true);
// Set the preferred parsers
oTxtLoadOptions.setPreferredParsers(new ICustomParser[] { new TextParser(), new DateParser() });
// Initialize the workbook object by passing CSV file and text load options
Workbook oExcelWorkBook = new Workbook(sourceDir + "samplePreferredParser.csv", oTxtLoadOptions);
// Get the first cell
Cell oCell = oExcelWorkBook.getWorksheets().get(0).getCells().get("A1");
// Display type of value
System.out.println("A1: " + getCellType(oCell.getType()) + " - " + oCell.getDisplayStringValue());
// Get the second cell
oCell = oExcelWorkBook.getWorksheets().get(0).getCells().get("B1");
// Display type of value
System.out.println("B1: " + getCellType(oCell.getType()) + " - " + oCell.getDisplayStringValue());
// Save the workbook to disc
oExcelWorkBook.save(outputDir + "outputsamplePreferredParser.xlsx");
System.out.println("OpeningCSVFilesWithPreferredParser executed successfully.\r\n");
}
private static String getCellType(int type){
if(type == CellValueType.IS_STRING){
return "String";
} else if(type == CellValueType.IS_NUMERIC){
return "Numeric";
} else if(type == CellValueType.IS_BOOL){
return "Bool";
} else if(type == CellValueType.IS_DATE_TIME){
return "Date";
} else if(type == CellValueType.IS_NULL){
return "Null";
} else if(type == CellValueType.IS_ERROR){
return "Error";
} else{
return "Unknown";
}
}

TSV(Sekmeyle Ayrılmış) Dosyalarını Açma

Sekmeyle ayrılmış dosyalar, herhangi bir biçimlendirme olmaksızın elektronik tablo verileri içerir. Veriler, tablolar ve elektronik tablolar gibi satırlar ve sütunlar halinde düzenlenir. Kısaca, sekmeyle ayrılmış bir dosya, metindeki her sütun arasında bir sekme bulunan özel bir tür düz metin dosyasıdır.

Sekmeyle ayrılmış dosyaları açmak için geliştiriciler**LoadOptions** sınıfı seçin ve**TSV** değer, önceden tanımlanmış**LoadFormat**numaralandırma.

Örnek vermek

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(OpeningTabDelimitedFiles.class) + "loading_saving/";
// Creating and TAB_DELIMITED LoadOptions object
LoadOptions loadOptions5 = new LoadOptions(LoadFormat.TSV);
// Creating an Workbook object with Tab Delimited text file path and the
// loadOptions object
Workbook workbook7 = new Workbook(dataDir + "Book1TabDelimited.txt", loadOptions5);
// Print message
System.out.println("Tab Delimited workbook has been opened successfully.");

Şifrelenmiş Excel Dosyalarını Açma

Microsoft Excel kullanarak şifreli Excel dosyaları oluşturmanın mümkün olduğunu biliyoruz. Bu tür şifrelenmiş dosyaları açmak için, geliştiricilerin özel bir aşırı yüklenmiş LoadOptions yöntemini çağırması ve FileFormatType numaralandırmasında önceden tanımlanmış olan VARSAYILAN değeri seçmesi gerekir. Bu yöntem, aşağıdaki örnekte gösterildiği gibi şifrelenmiş dosyanın şifresini de alacaktır.

Örnek vermek

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(OpeningEncryptedExcelFiles.class) + "loading_saving/";
// Opening Encrypted Excel Files
// Creating and EXCEL_97_TO_2003 LoadOptions object
LoadOptions loadOptions6 = new LoadOptions(LoadFormat.EXCEL_97_TO_2003);
// Setting the password for the encrypted Excel file
loadOptions6.setPassword("1234");
// Creating an Workbook object with file path and the loadOptions object
Workbook workbook8 = new Workbook(dataDir + "encryptedBook.xls", loadOptions6);
// Print message
System.out.println("Encrypted workbook has been opened successfully.");

Aspose.Cells ayrıca parola korumalı MS Excel 2013 dosyalarının açılmasını da destekler.

SXC Dosyalarını Açma

StarOffice Calc, Microsoft Excel’e benzer ve formülleri, çizelgeleri, işlevleri ve makroları destekler. Bu yazılımla oluşturulan elektronik tablolar SXC uzantısıyla kaydedilir. SXC dosyası, OpenOffice.org Calc elektronik tablo dosyaları için de kullanılır. Aspose.Cells, aşağıdaki kod örneğinde gösterildiği gibi SXC dosyalarını okuyabilir.

Örnek vermek

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the source directory.
String sourceDir = Utils.Get_SourceDirectory();
// Instantiate LoadOptions specified by the LoadFormat.
LoadOptions loadOptions = new LoadOptions(LoadFormat.SXC);
// Create a Workbook object and opening the file from its path
Workbook workbook = new Workbook(sourceDir + "SampleSXC.sxc", loadOptions);
// Using the Sheet 1 in Workbook
Worksheet worksheet = workbook.getWorksheets().get(0);
// Accessing a cell using its name
Cell cell = worksheet.getCells().get("C3");
System.out.println("Cell Name: " + cell.getName() + " Value: " + cell.getStringValue());

FODS Dosyalarını Açma

FODS dosyası, herhangi bir sıkıştırma olmadan OpenDocument XML’de kaydedilmiş bir elektronik tablodur. Aspose.Cells, aşağıdaki kod örneğinde gösterildiği gibi FODS dosyalarını okuyabilir.

Örnek vermek

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the source directory.
String sourceDir = Utils.Get_SourceDirectory();
// Instantiate LoadOptions specified by the LoadFormat.
LoadOptions loadOptions = new LoadOptions(LoadFormat.FODS);
// Create a Workbook object and opening the file from its path
Workbook workbook = new Workbook(sourceDir + "SampleFods.fods", loadOptions);
// Print message
System.out.println("FODS file opened successfully!");

ileri konular