Click here to Skip to main content
15,888,023 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone kindly let me know how to manipulate an image in XML spreadsheet 2003. I have an excel file which i am saving as an XML spreadsheet and i am manipulating the values in it based on the PHP code.. Now i want to place the company logo on the top for which i couldnt find any solution as of now..
Any help would be appreciated..

Thanks and Regards
Posted

1 solution

ExcelLibrary is open source project that provides native .NET features to comunicate with Microsoft Excel. It means that you will not need COM to create XLS spreadsheet anymore.

There is a way to embed any kind of image in a XLS spreadsheet also.
string file = "C:\\temp\\newdoc.xls";
Workbook workbook = new Workbook();
Worksheet worksheet = new Worksheet("First Sheet");
worksheet.Cells[0, 1] = new Cell((short)1);
worksheet.Cells[2, 0] = new Cell(2.8);
worksheet.Cells[3, 3] = new Cell((decimal)3.45);
worksheet.Cells[2, 2] = new Cell("Text string");
worksheet.Cells[2, 4] = new Cell("Second string");
worksheet.Cells[4, 0] = new Cell(32764.5, "#,##0.00");
worksheet.Cells[5, 1] = new Cell(DateTime.Now, @"YYYY\-MM\-DD");
worksheet.Cells.ColumnWidth[0, 1] = 3000;
Picture pic = new Picture();
pic.Image = ExcelLibrary.SpreadSheet.Image.FromFile("C:\\temp\\myLogo.png");
pic.TopLeftCorner = new CellAnchor(5, 1, 0, 0);
pic.BottomRightCorner = new CellAnchor(12, 5, 592, 243);
worksheet.AddPicture(pic);
workbook.Worksheets.Add(worksheet);
workbook.Save(file);

As you can see the code above fill some cells and insert a PNG image.

Remember to define those namespaces as well:
C#
using ExcelLibrary.CompoundDocumentFormat;
using ExcelLibrary.BinaryDrawingFormat;
using ExcelLibrary.BinaryFileFormat;
using ExcelLibrary.SpreadSheet;


Seek for http://code.google.com/p/excellibrary/[^] to get further information.
 
Share this answer
 
Comments
scorpzonex 4-Jul-14 10:55am    
how to do it from memorystream or byte[] array?
Member 11633344 10-Dec-15 10:26am    
pic.Image = new Image(data, 61470);
(61470 if is .png, 61469 .jpeg, .bmp 61471)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900