Skip to content

842238-Prepare UG for loading and saving an Excel file in Google App Engine using XlsIO #1107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: hotfix/hotfix-v29.1.33
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Document-Processing-toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,14 @@
</li>
</ul>
</li>
<li>
<a href="/document-processing/excel/excel-library/net/loading-and-saving/loading-and-saving-excel-files-in-google-cloud-platform">Google Cloud Platform (GCP)</a>
<ul>
<li>
<a href="/document-processing/excel/excel-library/net/loading-and-saving/loading-and-saving-excel-files-in-google-app-engine">Google App Engine</a>
</li>
</ul>
</li>
<li>Cloud Storage
<ul>
<li>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
---
title: Loading and Saving Excel in Google App Engine | Syncfusion
description: Explains how to load and save an Excel files in Google App Engine using .NET Core Excel (XlsIO) library without Microsoft Excel or interop dependencies.
platform: document-processing
control: XlsIO
documentation: UG
---

# Loading and Saving Excel files in Google App Engine

Syncfusion<sup>&reg;</sup> XlsIO is a [.NET Core Excel library](https://www.syncfusion.com/document-processing/excel-framework/net-core/excel-library) used to create, read, edit and convert Excel documents programmatically without **Microsoft Excel** or interop dependencies. Using this library, you can **load and save an Excel document in Google App Engine**.

## Set up App Engine

Step 1: Open the **Google Cloud Console** and click the **Activate Cloud Shell** button.

![Activate Cloud Shell](GCP_Images/App_Engine_Getting_Started.png)

Step 2: Click the **Cloud Shell Editor** button to view the **Workspace**.

![Open Editor in Cloud Shell](GCP_Images/Activate_Cloud_Shell.png)

Step 3: Open **Cloud Shell Terminal**, run the following **command** to confirm authentication.

{% tabs %}
{% highlight c# tabtitle="CLI" %}

gcloud auth list

{% endhighlight %}
{% endtabs %}

![Authentication for App Engine](GCP_Images/Authentication.png)

Step 4: Click the **Authorize** button.

![Click Authorize button](GCP_Images/Authorize_Button.png)

## Create an application for App Engine

Step 1: Open Visual Studio and select the ASP.NET Core Web app (Model-View-Controller) template.

![Create ASP.NET Core Web application in Visual Studio](GCP_Images/CreateProject_Create_Excel.png)

Step 2: Configure your new project according to your requirements.

![Configure your project](GCP_Images/Configuration_GCP.png)

Step 3: Click the **Create** button.

![Click create button](GCP_Images/Additional_Information_Create_Excel.png)

Step 4: Install the [Syncfusion.XlsIO.Net.Core](https://www.nuget.org/packages/Syncfusion.XlsIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org).

![Install Syncfusion.XlsIO.Net.Core Nuget Package](Loading-and-Saving_images/Loading-and-Saving_images_img19.png)

N> Starting with v16.2.0.x, if you reference Syncfusion<sup>&reg;</sup> assemblies from trial setup or from the NuGet feed, you also have to add "Syncfusion.Licensing" assembly reference and include a license key in your projects. Please refer to this [link](https://help.syncfusion.com/common/essential-studio/licensing/overview) to know about registering Syncfusion<sup>&reg;</sup> license key in your application to use our components.

Step 5: Include the following namespaces in the **HomeController.cs** file.

{% tabs %}
{% highlight c# tabtitle="C#" %}

using Syncfusion.XlsIO;

{% endhighlight %}
{% endtabs %}

Step 6: A default action method named Index will be present in HomeController.cs. Right click on Index method and select **Go To View** where you will be directed to its associated view page **Index.cshtml**.

Step 7: Add a new button in the Index.cshtml as shown below.

{% tabs %}
{% highlight c# tabtitle="C#" %}

@{Html.BeginForm("LoadAndSaveDocument", "Home", FormMethod.Get);
{
<div>
<input type="submit" value="Load and Save Document" style="width:220px;height:27px" />
</div>
}
Html.EndForm();
}

{% endhighlight %}
{% endtabs %}

Step 8: Add a new action method **LoadAndSaveDocument** in HomeController.cs and include the below code snippet to **Load and Save an Excel Document**.
{% tabs %}
{% highlight c# tabtitle="C#" %}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(excelStream);

//Access first worksheet from the workbook.
IWorksheet worksheet = workbook.Worksheets[0];

//Set Text in cell A3.
worksheet.Range["A3"].Text = "Hello World";

//Save the Excel to MemoryStream
MemoryStream outputStream = new MemoryStream();
workbook.SaveAs(outputStream);

//Set the position
outputStream.Position = 0;

//Download the Excel document in the browser.
return File(outputStream, "application/msexcel", "Output.xlsx");
}
{% endhighlight %}
{% endtabs %}

## Move application to App Engine

Step 1: Open the **Cloud Shell editor**.

![Cloud Shell Editor](GCP_Images/Cloud_Shell_Editor.png)

Step 2: Drag and drop the sample from your local machine to **Workspace**.

![Open the Home Workspace](GCP_Images/Workspace_ExceltoPDF.png)

N> If you have your sample application in your local machine, drag and drop it into the Workspace. If you created the sample using the Cloud Shell terminal command, it will be available in the Workspace.

Step 3: Open the Cloud Shell Terminal and run the following **command** to view the files and directories within your **current Workspace**.

{% tabs %}
{% highlight c# tabtitle="CLI" %}

ls

{% endhighlight %}
{% endtabs %}

![Open the Home Workspace](GCP_Images/View_File_ExceltoPDF.png)

Step 4: Run the following **command** to navigate which sample you want run.

{% tabs %}
{% highlight c# tabtitle="CLI" %}

cd Load-and-save-Excel-document

{% endhighlight %}
{% endtabs %}

![Open the Home Workspace](GCP_Images/Navigate_ExceltoPDF.png)

Step 5: To ensure that the sample is working correctly, please run the application using the following command.

{% tabs %}
{% highlight c# tabtitle="CLI" %}

dotnet run --urls=http://localhost:8080

{% endhighlight %}
{% endtabs %}

![Run the application using command](GCP_Images/Run_Application_Command_ExceltoPDF.png)

Step 6: Verify that the application is running properly by accessing the **Web View** -> **Preview on port 8080**.

![Verify the application is running properly](GCP_Images/Web_View_ExceltoPDF.png)

Step 7: Now you can see the sample output on the preview page.

![Sample output in browser](GCP_Images/Ensure_Sample_GCP.png)

Step 8: Close the preview page and return to the terminal then press **Ctrl+C** for which will typically stop the process.

![Close the preview page](GCP_Images/Stop_Process_ExceltoPDF.png)

## Publish the application

Step 1: Run the following command in **Cloud Shell Terminal** to publish the application.

{% tabs %}
{% highlight c# tabtitle="CLI" %}

dotnet publish -c Release

{% endhighlight %}
{% endtabs %}

![Publish the application](GCP_Images/Publish_ExceltoPDF.png)

Step 2: Run the following command in **Cloud Shell Terminal** to navigate to the publish folder.

{% tabs %}
{% highlight c# tabtitle="CLI" %}

cd bin/Release/net8.0/publish/

{% endhighlight %}
{% endtabs %}

![Publish the application](GCP_Images/Navigate_Publish_Folder_ExceltoPDF.png)

## Configure app.yaml and docker file

Step 1: Add the app.yaml file to the publish folder with the following contents.

{% tabs %}
{% highlight c# tabtitle="CLI" %}

cat <<EOT >> app.yaml
env: flex
runtime: custom
EOT

{% endhighlight %}
{% endtabs %}

![Add required files to publish folder](GCP_Images/Yaml_File_ExceltoPDF.png)

Step 2: Add the Docker file to the publish folder with the following contents.

{% tabs %}
{% highlight c# tabtitle="CLI" %}

cat <<EOT >> Dockerfile
FROM mcr.microsoft.com/dotnet/aspnet:8.0
RUN apt-get update -y && apt-get install libfontconfig -y
ADD / /app
EXPOSE 8080
ENV ASPNETCORE_URLS=http://*:8080
WORKDIR /app
ENTRYPOINT [ "dotnet", "Load-and-save-Excel-document.dll"]
EOT

{% endhighlight %}
{% endtabs %}

![Add required files to publish folder](GCP_Images/Docker_File_ExceltoPDF.png)

Step 3: You can ensure **Docker** and **app.yaml** files are added in **Workspace**.

![Add required files to publish folder](GCP_Images/Check_Yaml_Docker_ExceltoPDF.png)

## Deploy to App Engine

Step 1: To deploy the application to the App Engine, run the following command in Cloud Shell Terminal. Afterwards, retrieve the **URL** from the Cloud Shell Terminal.

{% tabs %}
{% highlight c# tabtitle="CLI" %}

gcloud app deploy --version v0

{% endhighlight %}
{% endtabs %}

!["Add required files to publish folder](GCP_Images/Deploy_ExceltoPDF.png)

Step 2: Open the **URL** to access the application, which has been successfully deployed.

!["Add required files to publish folder](GCP_Images/Browse_GCP.png)

By executing the program, you will get the **Excel document** as follows.

![Output File](Loading-and-Saving_images/Loading-and-Saving_images_img30.png)

Click [here](https://www.syncfusion.com/document-processing/excel-framework/net-core) to explore the rich set of Syncfusion<sup>&reg;</sup> Excel library (XlsIO) features.

An online sample link to [create an Excel document](https://ej2.syncfusion.com/aspnetcore/Excel/Create#/material3) in ASP.NET Core.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: Loading and Saving Excel in GCP | Syncfusion
description: Learn how to load and save an Excel files in Google Cloud Platform (GCP) using .NET Core Excel library (XlsIO).
platform: document-processing
control: XlsIO
documentation: UG
---

# Loading and Saving Excel files in Google Cloud Platform (GCP)

Syncfusion<sup>&reg;</sup> XlsIO is a [.NET Core Excel library](https://www.syncfusion.com/document-processing/excel-framework/net-core/excel-library) used to create, read, edit and convert Excel documents programmatically without **Microsoft Excel** or interop dependencies. Using this library, you can **load and save an Excel document in Google Cloud Platform (GCP)** within a few lines of code.

N> If this is your first time working with Google Cloud Platform (GCP), please refer to the dedicated GCP resources. This section explains how to load and save an Excel document in C# using the .NET Core Exel (XlsIO) library in GCP.

## Prerequisites

Before we begin, make sure you have the following.

* A [Google Cloud Platform (GCP)](https://console.cloud.google.com/getting-started) account with access to the App Engine service.

## Google Cloud Platform (GCP)

<table>
<thead>
<tr>
<th>
Google Cloud Platform<br/></th><th>
NuGet package name<br/></th></tr></thead>
<tr>
<td>
App Engine
<br/></td><td>
{{'[Syncfusion.XlsIO.Net.Core](https://www.nuget.org/packages/Syncfusion.XlsIO.Net.Core)' | markdownify}}<br/>
</td></tr>
</table>