Images into Excel SpreadSheet without giving cell information

Hi All,

I am using Aspose.cells, I want to export Images whicch are on my ASP.Net page along with data on it.

I could end up with proper data but I am not able to export images as I dont want to specify the cell position, this is because I have many files in which image's position differs. Hope you got my question.

Could you please provide me with the sample of code if possible, for exporting images into excel without Specific cell information or any other method.

Thanks in Advance,

Laxman.

Hi Laxman,

I am not sure about your need.....I dont want to specify the cell position, this is because I have many files in which image's position differs..... Could you elaborate it, thanks.

For extracting images into MS Excel Sheets you may check the following doc:

http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/adding-pictures.html

Thank you.

Hi,

worksheet.Pictures.Add(5,5,"C:\\image.gif");

In the above code I have to provide the specific cell position as parameter, where as I have many images on my web page, so I want to export them into excel randomly. i.e. I dont have any fixed position(cell) for any picture, it exports along with data. My Question is how to export images into excel withougt givining such rigid position.

Hope you guys understood,

Thanks,

Laxman.

Hi,

If you want insert images with data into a sheet continuously, you may use Cells.MaxDataRow, Cells.MaxDataColumn attributes to specify a table matrix (a table's last row and column) after putting the table (data) into the sheet.

May the following sample code help you for your need, The code just provides a hint (how you can do it) so kindly change the code accordingly. And attached is the output file (I used two datatable from Northwind.mdb and two sample images):

Sample code:

OleDbConnection con = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=f:\\test\\Northwind.mdb");
con.Open();
OleDbCommand cmd = new OleDbCommand("Select * from Products", con);
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;

DataSet ds = new DataSet();
da.Fill(ds, "Products");
DataTable dt = ds.Tables["Products"];

cmd = new OleDbCommand("Select * from Customers", con);
da.SelectCommand = cmd;
da.Fill(ds, "Customers");
DataTable dt1 = ds.Tables["Customers"];

Workbook workbook = new Workbook();
Aspose.Cells.Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;

int i = 0;
int maxdrow = 0;

//add the first pic along with the datatable
worksheet.Pictures.Add(maxdrow, 0, "f:\\test\\school.jpg");
Picture picture = worksheet.Pictures[i];
int row = picture.LowerRightRow ;
int col = picture.LowerRightColumn;
cells.ImportDataTable(dt1, false, row, col+1,false);

//Get the last row and column (matrix crieteria for table1) and specify
//the next position for the next set.
maxdrow = cells.MaxDataRow + 5;


//Add the second picture along with the table2
worksheet.Pictures.Add(maxdrow, 0, "f:\\test\\1978316911PurchasingReport.xml_img0.jpg");
picture = worksheet.Pictures[i+1];
row = picture.LowerRightRow;
col = picture.LowerRightColumn;
cells.ImportDataTable(dt, false, row, col + 1,false);


workbook.Save("f:\\test\\out_importngcontimages1.xls");

Thank you.