Начиная
Установка
Установите с Aspose.Cells по NuGet
NuGet — это самый простой способ загрузить и установить Aspose.Cells for .NET.
- Откройте Microsoft Visual Studio и диспетчер пакетов NuGet.
- Введите в поиске «aspose.cells» нужный номер Aspose.Cells for .NET.
- Нажмите «Установить», Aspose.Cells for .NET будет загружен и указан в вашем проекте.
Вы также можете загрузить его с веб-страницы nuget для aspose.cells: Aspose.Cells for .NET NuGet Пакет
Установите Aspose.Cells на Windows
- Загрузите Aspose.Cells.msi со следующей страницы: Скачать Aspose.Cells.msi
- Дважды щелкните msi Aspose Cells и следуйте инструкциям по его установке:
Установите Aspose.Cells на линукс
В этом примере я использую Ubuntu, чтобы показать, как начать использовать Aspose.Cells в Linux.
- Создайте приложение .netcore с именем «AsposeCellsTest».
- Откройте файл “AsposeCellsTest.csproj”, добавьте в него следующие строки для ссылок на пакеты Aspose.Cells:
<ItemGroup> <PackageReference Include="Aspose.Cells" Version="22.12" /> </ItemGroup>
- Откройте проект с помощью VSCode в Ubuntu:
- запустите тест со следующим кодом:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET Aspose.Cells.Workbook wb1 = new Aspose.Cells.Workbook(); wb1.Worksheets.Add("linux"); wb1.Worksheets["linux"].Cells[0, 0].Value = "Using Aspose Cells on linux with VS Code."; wb1.Save("linux.xlsx");
Примечание. Aspose.Cells Для .NetStandard может поддерживать ваши требования к Linux.
Применяется к: NetStandard2.0, NetCore2.1, NetCore3.1, Net5.0, Net6.0 и расширенной версии.
Установите Aspose.Cells на MAC OS
В этом примере я использую macOS High Sierra, чтобы показать, как начать использовать Aspose.Cells в MAC OS.
- Создайте приложение .netcore с именем «AsposeCellsTest».
- Откройте приложение с помощью Visual Studio для Mac, затем установите номера с Aspose от Cells до NuGet:
- запустите тест со следующим кодом:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET Aspose.Cells.Workbook wb1 = new Aspose.Cells.Workbook(); wb1.Worksheets.Add("macOS"); wb1.Worksheets["macOS"].Cells[0, 0].Value = "Using Aspose Cells on macOS with Visual Studio For MAC."; wb1.Save("macOS.xlsx"); - Если вам нужно использовать функции, связанные с рисованием, установите libgdiplus в macOS, см.: Как установить libgdiplus в macOS
Примечание: Aspose.Cells For .NetStandard может поддерживать ваши требования к MAC OS.
Применяется к: NetStandard2.0, NetCore2.1, NetCore3.1, Net5.0, Net6.0 и расширенной версии.
Запустите Aspose Cells в Docker
Как использовать графическую библиотеку на платформах, отличных от Windows, с Net6
Aspose.Cells для Net6 теперь использует SkiaSharp в качестве графической библиотеки, как рекомендовано вофициальное заявление от Microsoft . Дополнительные сведения об использовании Aspose.Cells с NET6 см.Как запустить Aspose.Cells для .Net6.
Создание приложения Hello World
Следующие шаги создают приложение Hello World, используя Aspose.Cells API:
- Если у вас есть лицензия, топрименить это. Если вы используете ознакомительную версию, пропустите строки кода, связанные с лицензией.
- Создайте экземплярРабочая тетрадь class для создания нового файла Excel или открытия существующего файла Excel.
- Получите доступ к любой нужной ячейке рабочего листа в файле Excel.
- Вставьте словаHello World! в ячейку, к которой осуществляется доступ.
- Создайте измененный файл Excel Microsoft.
Реализация вышеуказанных шагов продемонстрирована на примерах ниже.
Пример кода: создание новой книги
В следующем примере создается новая книга с нуля, вставляется “Hello World!” в ячейку A1 на первом листе и сохраняет как файл Excel.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
try | |
{ | |
// Create a License object | |
License license = new License(); | |
// Set the license of Aspose.Cells to avoid the evaluation limitations | |
license.SetLicense(dataDir + "Aspose.Cells.lic"); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
// Instantiate a Workbook object that represents Excel file. | |
Workbook wb = new Workbook(); | |
// When you create a new workbook, a default "Sheet1" is added to the workbook. | |
Worksheet sheet = wb.Worksheets[0]; | |
// Access the "A1" cell in the sheet. | |
Cell cell = sheet.Cells["A1"]; | |
// Input the "Hello World!" text into the "A1" cell | |
cell.PutValue("Hello World!"); | |
// Save the Excel file. | |
wb.Save(dataDir + "MyBook_out.xlsx"); |
Пример кода: открытие существующего файла
В следующем примере открывается существующий файл шаблона Excel Microsoft «Sample.xlsx», вставляется «Hello World!» в ячейку A1 на первом листе и сохраняет как файл Excel.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
try | |
{ | |
// Create a License object | |
License license = new License(); | |
// Set the license of Aspose.Cells to avoid the evaluation limitations | |
license.SetLicense("Aspose.Cells.lic"); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
// Creating a file stream containing the Excel file to be opened | |
FileStream fstream = new FileStream(dataDir + "Sample.xlsx", FileMode.Open); | |
// Instantiate a Workbook object that represents the existing Excel file | |
Workbook workbook = new Workbook(fstream); | |
// Get the reference of "A1" cell from the cells collection of a worksheet | |
Cell cell = workbook.Worksheets[0].Cells["A1"]; | |
// Put the "Hello World!" text into the "A1" cell | |
cell.PutValue("Hello World!"); | |
// Save the Excel file | |
workbook.Save(dataDir + "HelloWorld_out.xlsx"); | |
// Closing the file stream to free all resources | |
fstream.Close(); |