Coder Social home page Coder Social logo

aspose-cells-cloud / aspose-cells-cloud-dotnet Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 3.0 36.13 MB

.NET SDK to communicate with the Aspose.Cells REST API. Create, Edit & Convert Excel files in the Cloud.

Home Page: https://products.aspose.cloud/cells/net

License: MIT License

C# 82.74% Batchfile 0.01% HTML 17.22% PowerShell 0.04%
cloud-sdk aspose worksheet spreadsheet xlsb mhtml ods microsoft nuget listobjects

aspose-cells-cloud-dotnet's People

Contributors

babar-raza avatar naeem244 avatar nickliuaspose avatar roywangaspose avatar xuejianzhangd avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

aspose-cells-cloud-dotnet's Issues

C# Aspose.Cells.Cloud: Method to Convert to PDF fails intermittently

One of the features of our application is to create multiple books by converting the excel and word documents to PDF and ultimately merging them into a single PDF. The following code snippet is from the service worker task.

`private async Task ConvertToPdf(string fileUri, string guid, string bookFileName)
{
try
{
_telemetryTracker.TrackTrace(string.Format("File URI: {0}", fileUri), true);
var fileInfo = fileUri.Split("/");

            CloudStorageAccount account = null;
            CloudBlobContainer cloudBlobContainer = null;
            MemoryStream memstream = new MemoryStream();

            if (CloudStorageAccount.TryParse(_settings.CloudStorageConnection, out account))
            {
                var splitext = fileInfo[2].Split(".");
                var fileNameNoExt = Path.GetFileNameWithoutExtension(fileInfo[2]);
                var ext = splitext[splitext.Length - 1];
                CloudBlobClient client = account.CreateCloudBlobClient();
                var container = client.GetContainerReference(fileInfo[1]);
                var blob = container.GetBlockBlobReference(fileInfo[2]);

                if (ext == "xlsx" || ext == "xls" || ext == "xlsm")
                {
                    var apiInstance = new CellsApi(_settings.AsposeClientId, _settings.AsposeClientKey);
                    var name = fileInfo[2];  // string | The document name.
                    string needRemovedSheet = "Sheet1";
                    string needRemovedSheet1 = "Sheet2";
                    string needRemovedSheet2 = "Sheet3";
                    string needRemovedSheet3 = "Sheet4";
                    string needRemovedSheet4 = "Sheet5";
                    string needRemovedSheet5 = "Sheet6";
                    PdfSaveOptions saveOptions = new PdfSaveOptions(); // SaveOptions | Save options. (optional) 
                    saveOptions.SaveFormat = "pdf";
                    saveOptions.OnePagePerSheet = true;
                    var newfilename = $"converted/{fileNameNoExt}.pdf";  // string | The new file name. (optional) 
                    var isAutoFitRows = false;  // bool? | Autofit rows. (optional)  (default to false)
                    var isAutoFitColumns = false;  // bool? | Autofit columns. (optional)  (default to false)
                    var folder = "refresh";  // string | The document folder. (optional) 
                    var storage = _settings.AsposeStorageName;  // string | storage name. (optional) 
                    //remove specified worksheets from excel sheets 
                    await apiInstance.CellsWorksheetsDeleteWorksheetAsync(name, needRemovedSheet, folder, storage);
                    await apiInstance.CellsWorksheetsDeleteWorksheetAsync(name, needRemovedSheet1, folder, storage);
                    await apiInstance.CellsWorksheetsDeleteWorksheetAsync(name, needRemovedSheet2, folder, storage);
                    await apiInstance.CellsWorksheetsDeleteWorksheetAsync(name, needRemovedSheet3, folder, storage);
                    await apiInstance.CellsWorksheetsDeleteWorksheetAsync(name, needRemovedSheet4, folder, storage);
                    await apiInstance.CellsWorksheetsDeleteWorksheetAsync(name, needRemovedSheet5, folder, storage);
                    // Convert document and save result to storage.
                    Aspose.Cells.Cloud.SDK.Model.SaveResponse result = apiInstance.CellsSaveAsPostDocumentSaveAs(name, saveOptions, newfilename, isAutoFitRows, isAutoFitColumns, folder, storage);
                    LogInformation($"Successfully converted: {name} to PDF for {bookFileName}");
                }
                else if (ext == "docx" || ext == "doc" || ext == "dotx")
                {
                    CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileInfo[2]);
                    await blockBlob.DownloadToStreamAsync(memstream);

                    var format = "pdf";
                    WordsApi WordsApi = new WordsApi(_settings.AsposeClientId, _settings.AsposeClientKey);
                    memstream.Position = 0;  //reset stream position so it's not starting at EOF
                    var request = new ConvertDocumentRequest(memstream, format);
                    var result = WordsApi.ConvertDocument(request);
                    var cont = client.GetContainerReference("refresh");
                    var newfilename = $"converted/{fileNameNoExt}.pdf";
                    CloudBlockBlob bl = cont.GetBlockBlobReference(newfilename);
                    await bl.UploadFromStreamAsync(result);
                    LogInformation($"Properly Converted file: {newfilename} for {bookFileName}");
                }
            }
        }
        catch (Exception ex)
        {
            _telemetryTracker.TrackException(new Exception("Failed to convert the file to pdf",ex));
            throw;
        }
    }`

Intermittently this process fails i.e It doesn’t throw any exceptions but simply crashes midway. Looking at the logs, I see that it fails to convert all the excel templates into PDF ( There are 14 excel templates that needs to be converted to PDF in our case and the call to this method is in a for loop) but the traces show ‘FileURI: filename’ message for every document and only few ‘successfully converted’ or ‘properly converted’ messages ( we are writing these messages to logs as shown in the above code). Couldn’t find anything when debugged and is successful each time. Can anyone please guide me to proceed further?
Any help is greatly appreciated. Thank you in advance.

PS: Noticed that this usually happens when multiple books (4 in our case) are created at the same time. They are multi-threaded processes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.