The excel spread sheet is a powerful Office tool developed by Microsoft. The latest Excel supports maximum [see this] 1,048,576 rows by 16,384 columns, which i believe you will never ever have to use in your life.
The excel spread sheet is often used to put numbers, equations (formulas) in, so you can easily have something easy, straightforward yet powerful worksheet, such as invoice. But, we are going to experiment something for fun in excel. We are going to change the colour of each cell in Excel, which will display a picture in excel spread sheet.
We all know the VBScript is a powerful scripting tool that can be used to run administrative tasks on Windows Scripting Host environment. So the following is a piece of code that changes the colour of the first cell using VBScript, that invokes the COM object Excel.Application which is available after you install Excel.
1 2 3 4 5 6 7 8 9 10 11 12 13 | Set objExcel = CreateObject("Excel.Application") ' Do not show GUI objExcel.Visible = False ' Suppress the dialogs, use the default option. objExcel.DisplayAlerts = False Set objWorkbook = objExcel.Workbooks.Add Set objWorksheet = objWorkbook.Worksheets(1) With objWorksheet .Cells(1,1).Interior.Color=RGB(245,245,245) End With objWorkbook.SaveAs("pic.xlsx") objExcel.Quit Msgbox "pic.xlsx saved!" |
Set objExcel = CreateObject("Excel.Application") ' Do not show GUI objExcel.Visible = False ' Suppress the dialogs, use the default option. objExcel.DisplayAlerts = False Set objWorkbook = objExcel.Workbooks.Add Set objWorksheet = objWorkbook.Worksheets(1) With objWorksheet .Cells(1,1).Interior.Color=RGB(245,245,245) End With objWorkbook.SaveAs("pic.xlsx") objExcel.Quit Msgbox "pic.xlsx saved!"
So, what we have to do now is to read a image (e.g. JPEG file) and process each pixel and output the VBScript code line by line, setting each cell colour. The below PHP code (you may use other programming language for sure), shows this idea.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | $url = "raspberrypi.jpg"; $image = imagecreatefromjpeg($url); $width = imagesx($image); $height = imagesy($image); for ($i = 1; $i < $height; $i ++) { for ($j = 1; $j < $width; $j ++) { $pixel_color = imagecolorat($image, $j, $i); $color_tran = imagecolorsforindex($image, $pixel_color); $r = $color_tran['red']; $g = $color_tran['green']; $b = $color_tran['blue']; echo ".Cells($i,$j).Interior.Color=RGB($r,$g,$b)\n"; } } |
$url = "raspberrypi.jpg"; $image = imagecreatefromjpeg($url); $width = imagesx($image); $height = imagesy($image); for ($i = 1; $i < $height; $i ++) { for ($j = 1; $j < $width; $j ++) { $pixel_color = imagecolorat($image, $j, $i); $color_tran = imagecolorsforindex($image, $pixel_color); $r = $color_tran['red']; $g = $color_tran['green']; $b = $color_tran['blue']; echo ".Cells($i,$j).Interior.Color=RGB($r,$g,$b)\n"; } }
Save the above code in *.vbs and double click, which will give a Excel file pic.xlsx. Open it,
Take a look at the excel file as well, [here] . There are too many colour pixels in excel sheet, and you might have to zoom out a little bit by using Ctrl + scroll button.
–EOF (The Ultimate Computing & Technology Blog) —
loading...
Last Post: Passing Variables through different pages in PHP
Next Post: Compress CSS Stylesheets to Save Download Bandwidths