本简短教程指导如何在 Docker 容器中安装 Dotnet 以使用 Aspose.Cells。它包含创建 Docker 镜像以在其中使用 Aspose.Cells for .NET 的详细步骤。最后,您将能够在可运行的示例代码的帮助下在 Linux 中处理 Excel,例如将XLSX、XLS、ODS 或 XLSM 转换为 PDF。
在 Docker 容器中安装 Dotnet 以使用 Aspose.Cells 的步骤
- 拉取适用于 Microsoft Dotnet 的 Docker 映像
- 运行容器并更新软件包以及软件包列表
- 安装 wget 命令
- 安装 sudo 命令
- 使用 sudo 命令安装 dotnet-sdk-3.1
- 安装 libgdiplus 和 libc6-dev 库
- 通过链接并打开主机上 Docker 容器中的项目文件夹来运行映像
- 运行测试程序
这些步骤通过详细的步骤描述了在 Ubuntu 上使用 Excel 的过程。假设您已经在系统上安装了 Docker 软件,然后开始拉取 Microsoft Dotnet 的 Docker 映像并运行此映像。在下一步中,要在 Ubuntu 中使用 Excel,需要安装必要的库和 SDK 以在 Docker 映像中开发和执行程序并将其提交到磁盘上。在最后一步中,将主机系统上的开发文件夹与 Docker 映像中的某个文件夹链接起来,并执行测试程序。
在 Docker 容器中安装 Dotnet 以使用 Aspose.Cells 的脚本
Environment Setting
It is assumed that you have installed docker on your computer and then pulled the microsoft/dotnet container as follows:
docker pull microsoft/dotnet
After pulling this image run it and run following script one by one in the terminal window.
Step 1:
apt update && apt upgrade
Step 2:
apt install wget
Step 3:
apt-get install sudo
Step 4:
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
Step 5:
sudo dpkg -i packages-microsoft-prod.deb
Step 6:
sudo apt-get update; \
sudo apt-get install -y apt-transport-https && \
sudo apt-get update && \
sudo apt-get install -y dotnet-sdk-3.1
Step 7:
sudo apt-get install libgdiplus
ln -s libgdiplus.so gdiplus.dll
Step 8:
sudo apt-get install libc6-devStep 1:
apt update && apt upgrade
Create a console-based project and put the following code in it.
Sample Code
As we are demonstrating the Excel to PDF conversion, your console application may look as follows:
// Instantiate new workbook
Workbook workbook = new Workbook("sample.xlsx");
// Define PdfSaveOptions
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
// Set the compliance type
pdfSaveOptions.Compliance = PdfCompliance.PdfA1b;
// Save the file
workbook.Save("output.pdf", pdfSaveOptions);
You can compile and run this application in your container as SDK is also installed. Link some of the folders on the host operating system and run the saved image having all the required libraries. Use the following command to load the image by connecting to the Desktop folder.
docker run -it -v ~/Desktop:/Desktop Microsoft/dotnet /bin/bash
Navigate to the project where the .proj file is present and run the application using the following command. It is assumed that the application is compiled already. You can compile it here as well if required.
dotnet run
该脚本有助于建立在 Docker 容器中运行 Aspose.Cells for .NET 的完整环境。在Linux中工作时,可以创建和处理具有完整功能的电子表格。您必须首先通过安装所需的库来准备容器,然后提交它以使更改永久生效。