How to open Excel file in C# in Linux

Hello vladimir.litvinchik

libgdiplus version is 6.0.5.

libgdiplus is already the newest version (6.0.5-0xamarin1+ubuntu2004b1)

The dockerfile you sent is the same as the dockerfile we have.

Since there is no function that gives the error in the example project you sent by saying that the excel file is working in Linux, it is normal that it works without an error. But the function giving error is as follows. These functions are the codes of the project in the URL below that you sent us.

It is the method in the ViewerController class under Controllers in the Viewer.UI.Api in this project.

Attached is the function that gives an error as in the document I sent you.
Error Screen Picture.zip (246.1 KB)

I checked the link you sent. libgdiplus version is 6.0.5. because the problem is different. PDF to PNG conversion issue on CentOS 7 - #14 by vladimir.litvinchik

[HttpGet]
        public async Task<IActionResult> LoadDocumentDescription(string ep)
        {
            try
            {
                //string storagePath = Path.Combine(new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).Parent.FullName, "MyStaticFiles");
                //string filepath = string.Format("{0}\\{1}", storagePath, ep + ".png");

                DocumentInfo documentDescription =
                    await _viewer.GetDocumentInfoAsync(ep, "");

                var result = new LoadDocumentDescriptionResponse
                {
                    Guid = ep,
                    PrintAllowed = documentDescription.PrintAllowed,
                    Pages = documentDescription.Pages.Select(p => new PageDescription
                    {
                        Width = p.Width,
                        Height = p.Height,
                        Number = p.Number,
                        SheetName = p.Name,
                    }).ToList()
                };

                return OkJsonResult(result);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("password", StringComparison.InvariantCultureIgnoreCase))
                {
                    var message = string.IsNullOrEmpty("")
                            ? "Password Required"
                            : "Incorrect Password";

                    return ForbiddenJsonResult(message);
                }

                return ErrorJsonResult(ex.Message);
            }
        }

@kenankocer

Since you’re using GroupDocs.Viewer 21.7 please make sure to reference SkiaSharp.NativeAssets.Linux.NoDependencies 2.80.2.

Hi,

Although the packages are already installed in this way, groupdocs gives the error I showed above in the LoadDocumentDescription(string ep) method when opening excel in linux.Packages.png (4.6 KB)

@kenankocer

Thank you for the response. We’ll try to reproduce this issue and will update you as soon as we have any new information.

Hi @vladimir.litvinchik

Our customers use the application in a live environment. That’s why it’s important to us. I wanted to ask if there is any progress.

Thanks for be interested.

@kenankocer

Unfortunately, I can’t reproduce this issue when running it in Docker. Here are the steps that I’ve performed to reproduce the issue:

  1. Cloned the repository git clone https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-.NET-UI.git
  2. Removed .git and .github folders
  3. Removed GroupDocs.Viewer.UI.Cloud.Api.Sample and GroupDocs.Viewer.UI.SelfHost.Api.Service.Sample in the samples folder
  4. Updated the following lines in build/dependencies.props file
    • <GroupDocsViewer>22.1.1</GroupDocsViewer> to
      <GroupDocsViewer>21.7.0</GroupDocsViewer>
    • <SkiaSharpNativeAssetsLinuxNoDependencies>2.80.3</SkiaSharpNativeAssetsLinuxNoDependencies> to <SkiaSharpNativeAssetsLinuxNoDependencies>2.80.2</SkiaSharpNativeAssetsLinuxNoDependencies>
  5. Added Excel files to samples\GroupDocs.Viewer.UI.Sample\Files\ folder
  6. Added .dockerignore to the root folder
  7. Placed Dockerfile in samples\GroupDocs.Viewer.UI.Sample\
  8. Built image from the root folder by running docker build -f samples/GroupDocs.Viewer.UI.Sample/Dockerfile -t groupdocs-viewer-ui:sample-app .
  9. Started the container with docker run -d -p 8080:80 --name viewer-demo groupdocs-viewer-ui:sample-app
  10. Navigated to http://localhost:8080/viewer in a browser
  11. Opened Excel files

I’m attaching the files and sample app:

Can you please try running the attached app with your file in Docker and confirm that you can reproduce the issue?

Hi Vladimir.litvinchik,

When we synchronized our project with the project you sent, we solved the excel problem. But there is a situation like this, in the project you sent, it loads all of the documents with more than 2 pages or sheets as 2 pages and shows them as 2 pages. How can we fix this?error1.png (21.2 KB)

@kenankocer

Thank you for attaching the screenshot with the error. This is evaluation limitation, the license should be set. You can copy a license (.lic) file to samples\GroupDocs.Viewer.UI.Sample\ folder, then add it to the output directory in the GroupDocs.Viewer.UI.Sample.csproj file

  <ItemGroup>
    <None Update="GroupDocs.Viewer.lic">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

And set a path to license file in samples\GroupDocs.Viewer.UI.Sample\Startup.cs:

services
    .AddControllers()
    .AddGroupDocsViewerSelfHostApi(config =>
    {
        config.SetLicensePath("GroupDocs.Viewer.lic");
    })
    .AddLocalStorage("./Files")
    .AddLocalCache("./Cache");

Rebuild the Docker image and try running the container again. In case the license is properly set you won’t see the trial limitation any more.

Please find attached changed-files.zip (1.0 KB).

Let us know if it worked for you.

Hi Vladimir.litvinchik

I added the lic file to the project. I edited the csproj as you said.project structure.png (12.1 KB)
csproj.png (9.6 KB)

However, after page 2, it does not load.page not loading.png (57.7 KB)

Unlike the project you sent, I call the LoadDocumentDescription method from within the .ts file. Could it be caused by this?code.png (42.3 KB)

Thank you.

@kenankocer

Please try removing the cache files. In case the issue still exists can you check if there are any errors in the browser developer console F12?

Hi ,

I cleared the cache and cache, it’s not related to it.

When we call the LoadDocumentDescription method from the code, it does not load after the 2nd page and the back and forth buttons do not work.
code.png (42.3 KB)
error1.png (47.6 KB)
error2.png (39.7 KB)
error3.png (40.6 KB)

However, everything works when the document wants to be opened from the button that opens the document tree.
error4.png (48.5 KB)
error5.png (41.1 KB)
error6.png (37.4 KB)

I guess there are methods that trigger something in between. How can I find.

@kenankocer

You can try to run the client (Angular App) from sources to find where the code throws.

  • Navigate to the samples\GroupDocs.Viewer.UI.Sample\ and enable CORS in Startup.cs
public void ConfigureServices(IServiceCollection services)
{
    services.AddCors(options => 
        options.AddPolicy("AllowAll", builder =>
        {
            builder
                .AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader();
        }));

...

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseCors("AllowAll");

...
  • Navigate to src\GroupDocs.Viewer.UI\client\src\app\
  • Update configServiceFactory method in app.module.ts to
export function configServiceFactory() {
  let apiEndpoint = 'http://localhost:5000/viewer-api';
  let uiSettingsPath = 'http://localhost:5000/viewer-config';

  let config = new ConfigService();
  config.apiEndpoint = apiEndpoint;
  config.getViewerApiEndpoint = () => apiEndpoint;
  config.getConfigEndpoint = () => uiSettingsPath;
  return config;
}
  • Install packages npm install
  • Run the app ng serve
  • Navigate to http:\\localhost:4200 and try reproducing the issue.
  • Check the browser console for error and explore the code that throws.

Attaching changed-files.zip (1.7 KB) for more details.

Hi,

I fixed the problems.

Thank you very much for your interest.

@kenankocer

Thank you for your feedback!

Can you please share what was the issue?

Hi,
I made an improvement on creating an external dowload link and sending it directly to GroupDocs as a url and opening it. In order to achieve this, I added this code block to the app.component.ts file, but since I did not import ngOninit, there was an error on page loads here. Forward and Back buttons, on the other hand, could not work properly because they could not see it in ngoninit because they looked at the navigateService component. That’s why I did the imports.

1.png (14.9 KB)
2.png (29.7 KB)
3.png (13.4 KB)

@kenankocer

Thank you for sharing the details!

Have a nice day

Vladimir Litvinchik

Have a nice day

1 Like

@kenankocer

Thank you!

Hello,

I downloaded the groupdocs annotation application at the address and ran it.

I upload the file and add annotation on it and press the save button.

When I look at the code, I expect another file with the _tmp extension to be created, but it does not.
picture2.png (10.7 KB)
picture1.png (57.0 KB)

Can you check?

@kenankocer

This question was answered at GroupDocs Annotation WebForm Save Button İs Not Working.