Inserting .gif file from server to excel sheet

Hi,

I have one image file(.gif/.jpg) in a https server (ex:- http://www.mkyong.com/image/mypic.jpg). I need to insert that image to an excel sheet using Aspose Cells java. Could you please suggest me .

Hi Kishore,


Thank you for contacting Aspose support.

Please review the article on how to insert the image (from remote location) to Worksheet. Hope it helps you achieve your goal.

Hi Babar,

Thank you . I am able to load the image now but i am facing one issue like the image is getting loaded in the excel sheet only after 15 to 20 seconds.Is there something I need to do for this?

Hi Kishore,


Please note, the Aspose.Cells APIs will first fetch the image from the remote location and then add it to the worksheet therefore the delay mainly depends on the image size as well as the strength of your internet connection.

Hi,

I have one sheet with name ‘History’ in the workbook. I need to delete that sheet in runtime in some cases and again create it with the same name. I am using below code to delete the sheet but it is not entering into the loop. Is there any API for this ?

if(workBook.getWorksheets().contains(“History”))
{
workBook.getWorksheets().removeAt(“History”);
}

Hi Kishore,


You do not need to loop over the WorksheetCollection to delete a particular Worksheet as you can simply call the removeAt method while specifying the target Worksheet index or name.

Java

Workbook book = new Workbook(dir + “newtest.xlsx”);
WorksheetCollection worksheets = book.getWorksheets();
worksheets.removeAt(“sheet1”);

Please note, it is advised to create a new thread for every distinct problem you encounter with Aspose APIs. This will simply help us track your requests efficiently. Moreover, the information shared in the public forums is for every member of the community, therefore providing appropriate thread title helps in finding the relevant information quickly.

Hi,

I am using the below method to render an image from the server to my excel report.
Picture pic = sheetName.getShapes().addLinkedPicture(1, 1, 100, 100, “serverpath);
After generating the report when I open it , it is taking too much time to load that image . First i am getting blank page & after some time the image coming only after clicking on that sheet.
Is there any way to improve the performance? Could you please suggest me.

Hi Kishore,


Do you mean that the image in the spreadsheet takes time to load when you view the spreadsheet in Excel? If so, please provide us an executable sample application (with all its dependencies) along with resultant spreadsheet (generated on your end) in order to investigate the said scenario on our side. Please keep the sample project simple focusing on the mentioned issue only. Moreover, please provide details of your environment as follow.

  • Operating system version & architecture.
  • JDK vendor, version & architecture.
  • Aspose.Cells for Java version being used for spreadsheet generation.
  • Version of Excel application used to load the Aspose.Cells’ generated spreadsheet.
  • JVM arguments set for the spreadsheet generation process, if any.

Looking forward to above information/artifacts to assist you further in this regard.

Hi,

Is there any code to download the image to a memory stream & after that adding that image to a worksheet just like below C# code.

var webClient = new WebClient();
byte[] imgBytes = webClient.DownloadData(logoPath);
MemoryStream ms = new MemoryStream();
ms.Write(imgBytes, 0, imgBytes.Length);

Picture picture = worksheet.Shapes.AddPicture(0, 0, ms, 100, 100);

Hi,


You may try the following snippet.

Java

java.net.URL url = new java.net.URL("http://www.aspose.com/Images/Newsletter/Dec-2015/25percent-off-aspose-total-big.png");
java.awt.Image bufferedImage = javax.imageio.ImageIO.read(url);
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
javax.imageio.ImageIO.write((RenderedImage) bufferedImage, “png”, baos);
java.io.InputStream stream = new java.io.ByteArrayInputStream(baos.toByteArray());
com.aspose.cells.Workbook book = new com.aspose.cells.Workbook();
com.aspose.cells.Worksheet sheet = book.getWorksheets().get(0);
sheet.getShapes().addPicture(0, 0, 13, 4, stream);
book.save(dir + “output.xlsx”);

Hi,

I have tried above code & I am getting below exception.
javax.imageio.IIOException: Can’t get input stream from URL!

Hi Kishore,


Well, I have tested the code before suggesting it to you, that mean; I am able to get the correct results with it. I have tested it again with a sample URL of my own and I am not able to observe any exception. Moreover, you do not need to use this approach because Aspose.Cells for Java APIs provide the direct means to insert the picture from any remote location.

Anyway, as requested here, please provide the details of your environments as well as the URL to you sample image so we could test the performance concerns in perspective of ShapesCollection.addLinkedPicture method.