EasyXLS™ library allows you to export images to Excel and add the images to Excel sheets like worksheets or chart sheets. The image is automatically inserted with the original size, but the size can be changed later. The width and height of the image must be specified in pixels.
EasyXLS also allows reading images from Excel files.
The library supports images in JPG, GIF, PNG, BMP and TIF file format. The old XLS file format supports only JPEG images.
The below example shows how to export an image to an Excel sheet.
The source code samples can be integrated in:
- ASP.NET web pages - Windows applications - Windows Forms (WinForms) - Console applications - Windows service applications - ASP.NET MVC web applications - PHP and ASP web pages - Java applications
// Create an instance of the class that exports Excel files, having two sheets
ExcelDocument workbook = new ExcelDocument(2);
// Add the image to the first sheet
((ExcelWorksheet)workbook.easy_getSheetAt(0)).easy_addImage(
"C:\\Samples\\EasyXLSLogo.JPG", "A1");
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Exported image to Excel.xlsx");
' Create an instance of the class that exports Excel files, having two sheetsDim workbook As New ExcelDocument(2)
' Add the image to the first sheetDim xlsFirstTab As ExcelWorksheet = workbook.easy_getSheetAt(0)
xlsFirstTab.easy_addImage("C:\Samples\EasyXLSLogo.JPG", "A1")
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Exported image to Excel.xlsx")
C++// Create an instance of the class that exports Excel files
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook) ;
// Create two sheets
workbook->easy_addWorksheet_2("First tab"
workbook->easy_addWorksheet_2("Second tab");
// Add the image to the first sheet
EasyXLS::IExcelWorksheetPtr xlsFirstTab =
(EasyXLS::IExcelWorksheetPtr)workbook->easy_getSheetAt(0);
xlsFirstTab->easy_addImage_5("C:\\Samples\\EasyXLSLogo.JPG", "A1");
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Exported image to Excel.xlsx");
Click here to see Continuous Code ListingC++.NET// Create an instance of the class that exports Excel files, having two sheets
ExcelDocument ^workbook = gcnew ExcelDocument(2);
// Add the image to the first sheet
ExcelWorksheet ^xlsFirstTab =
safe_cast<ExcelWorksheet^>(workbook->easy_getSheetAt(0));
xlsFirstTab->easy_addImage("C:\\Samples\\EasyXLSLogo.JPG", "A1");
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Exported image to Excel.xlsx");
Click here to see Continuous Code Listing
// Create an instance of the class that exports Excel files, having two sheets
ExcelDocument workbook = new ExcelDocument(2);
// Add the image to the first sheet
((ExcelWorksheet)workbook.easy_getSheetAt(0)).easy_addImage(
"C:\\Samples\\EasyXLSLogo.JPG", "A1");
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Exported image to Excel.xlsx");
.NET:// Create an instance of the class that exports Excel files
$workbook = new COM("EasyXLS.ExcelDocument");
// Create two sheets
$workbook->easy_addWorksheet_2("First tab"
$workbook->easy_addWorksheet_2("Second tab");
// Add the image to the first sheet
$workbook->easy_getSheetAt(0)->easy_addImage_5("C:\\Samples\\EasyXLSLogo.JPG", "A1");
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Exported image to Excel.xlsx");
Click here to see Continuous Code ListingJava:// Create an instance of the class that exports Excel files
$workbook = new java("EasyXLS.ExcelDocument");
// Create two sheets
$workbook->easy_addWorksheet("First tab");
$workbook->easy_addWorksheet("Second tab");
// Insert image into sheet
$workbook->easy_getSheetAt(0)->easy_addImage("C:\\Samples\\EasyXLSLogo.JPG", "A1");
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Exported image to Excel.xlsx");
Click here to see Continuous Code Listing
' Create an instance of the class that exports Excel filesset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Create two sheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
' Add the image to the first sheet
workbook.easy_getSheetAt(0).easy_addImage_5 "C:\\Samples\\EasyXLSLogo.JPG", "A1"' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Exported image to Excel.xlsx")
' Create an instance of the class that exports Excel filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Create two sheets
workbook.easy_addWorksheet_2 ("First tab")
workbook.easy_addWorksheet_2 ("Second tab")
' Add the image to the first sheet
workbook.easy_getSheetAt(0).easy_addImage_5 "C:\\Samples\\EasyXLSLogo.JPG", "A1"' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Exported image to Excel.xlsx")
' Create an instance of the class that exports Excel filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Create two sheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
' Add the image to the first sheet
workbook.easy_getSheetAt(0).easy_addImage_5 "C:\\Samples\\EasyXLSLogo.JPG", "A1"' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Exported image to Excel.xlsx")
<!-- Create an instance of the class that exports Excel files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Create two sheets --><cfset ret = workbook.easy_addWorksheet("First tab")><cfset ret = workbook.easy_addWorksheet("Second tab")><!-- Add the image to the first sheet --><cfset workbook.easy_getSheetAt(0).easy_addImage(
"D:\\Development\\sources\\test_XLS\\EasyXLSLogo.JPG", "A1")><!-- Export Excel file --><cfset ret = workbook.easy_WriteXLSXFile("C:\Samples\Exported image to Excel.xlsx")>
.NET:# Create an instance of the class that exports Excel files having two sheets
workbook = ExcelDocument(2)
# Insert image into sheet
workbook.easy_getSheetAt(0).easy_addImage("C:\\Samples\\EasyXLSLogo.JPG", "A1")
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Exported image to Excel.xlsx")
Click here to see Continuous Code ListingJava:# Create an instance of the class that exports Excel files having two sheets
workbook = gateway.jvm.ExcelDocument(2)
# Insert image into sheet
workbook.easy_getSheetAt(0).easy_addImage("C:\\Samples\\EasyXLSLogo.JPG", "A1")
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Exported image to Excel.xlsx")
Click here to see Continuous Code Listing
The screen shot provides an example of a report that has an exported image to Excel file.