Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Fri Jul 31, 2015 5:35 pm

Hi, i have a webService method that creates a Excel file and use to work fine in my server, im moving to Windows Azure Storage and it is creating the file correctly, it creates the file with data (Size is not 0bytes) but when i try to open it the file is empty

I tried too many combinations if i use UploadFromStream the file is created empty.

MemoryStream stram = new MemoryStream();
workbook.SaveToStream(stram,Spire.Xls.FileFormat.Version97to2003);
blob.UploadFromStream(stram);

Mi function is this:
MemoryStream stram = new MemoryStream();
workbook.SaveToStream(stram,Spire.Xls.FileFormat.Version97to2003);

byte[] buffer = new byte[(int)stram.Length];
stram.Read(buffer, 0, (int)stram.Length);
CloudBlob blob = blobContainer.GetBlobReference(filename);
blob.UploadByteArray(buffer);

valmans
 
Posts: 2
Joined: Sun Jun 24, 2012 1:55 am

Mon Aug 03, 2015 10:20 am

Hello,

Thanks for your inquiry.
Could you please offer us the correct sample file and incorrect sample file that you created?
It would be helpful to replicate the issue and work out the solution for you ASAP.
Please kindly note that firstly you need to compress it and upload.
Or you can send it to us ( Support@e-iceblue.com ) via email.

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Mon Aug 03, 2015 6:06 pm

Many thanks, i solved it!.
Here the solution...

CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse("XXXX==");

CloudBlobClient blobClient = cloudStorageAccount.CreateCloudBlobClient();
CloudBlobContainer blobContainer = blobClient.GetContainerReference("exportaciones");

// If the container does not exist, we need to create it.
blobContainer.CreateIfNotExist();
// Let us put public permissions on the container so we can access the file from anywhere.
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
containerPermissions.PublicAccess = BlobContainerPublicAccessType.Blob;
blobContainer.SetPermissions(containerPermissions);
CloudBlob blob = blobContainer.GetBlobReference(filename);

MemoryStream stram = new MemoryStream();
workbook.SaveToStream(stram);

blob.UploadFromStream(stram);
stram.Seek(0, SeekOrigin.Begin);
blob.Properties.ContentType = "application/octet-stream ";
blob.SetProperties();
BlobRequestOptions options = new BlobRequestOptions();
options.AccessCondition = AccessCondition.None;
blob.UploadFromStream(stram, options);
String usi = blob.Uri.ToString();

valmans
 
Posts: 2
Joined: Sun Jun 24, 2012 1:55 am

Tue Aug 04, 2015 1:34 am

Hello,

Glad to hear that this problem has been solved.
Please feel free to contact us if you have any questions.

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Mon Jan 16, 2023 3:49 pm

Hi i am using spire to convert doc to html, i see below options

1. SaveToFile: This generate, Folder with images, css file, html. This we can not use, as we are trying to do this with azure func and local file generation is not supported here.
2. SaveToStream: This generate stream with html code and link to image is broken here. Please find the below code using for this purpose. Here, we are looking to generate proper stream which will display image properly.

BlobServiceClient blobServiceClient = new BlobServiceClient(cnn);
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);
var blobs = containerClient.GetBlobs();
foreach (BlobItem blobItem in blobs)
{
//convert .docx files
if (blobItem.Name.Contains(".docx"))
{
MemoryStream html = new MemoryStream();
BlobClient blobClient = containerClient.GetBlobClient(blobItem.Name);
if (blobClient.ExistsAsync().Result)
{
using (var docx = new MemoryStream())
{
blobClient.DownloadTo(docx);
//return ms.ToArray();
using (MemoryStream stream = new MemoryStream(docx.ToArray()))
{
Document spireDoc = new Document();
spireDoc.LoadFromStream(stream, FileFormat.Docx2013);
//the new docx without image
spireDoc.SaveToStream(html, FileFormat.Html);
html.Position = 0;
blobClient = containerClient.GetBlobClient(blobItem.Name.Replace(".docx", ".html"));
await blobClient.UploadAsync(html, true);
}
}
}
}

}

santosh4227
 
Posts: 5
Joined: Mon Jan 16, 2023 3:09 pm

Tue Jan 17, 2023 9:52 am

Hello,

Thanks for your inquiry.
For your issue, I suggest that the css file and image file are embeded in the result html before saving to stream. I put the code below for your reference.
Code: Select all
  //Open a Word document.
            Document document = new Document();
            document.LoadFromFile(@"..\..\data\ToHtmlTemplate.docx");
            //Setthe css styles are embeded.
            document.HtmlExportOptions.CssStyleSheetType = CssStyleSheetType.Internal;

            //Set the images are embeded.
            document.HtmlExportOptions.ImageEmbedded = true;

            //Set the option whether to export form fields as plain text or not.
            document.HtmlExportOptions.IsTextInputFormFieldAsText = true;

            //Save the result html to stream
            MemoryStream html = new MemoryStream();
            document.SaveToStream(html,FileFormat.Html);


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.XLS