当然是用excel画女神:
这个是用vbscript在excel里画的,原理就是读出bmp的数据,然后逐个像素地描到excel里。每个像素对应一个excel里的一个单元格。下面的代码可以把你的女神一行行地打印在excel里。由于vb运行得慢,你可以看到女神在excel里一行行被打印出来。 我看楼上 @叛逆者 同学画了个小黄人,可以使用同样的原理把小黄人画在excel里,你只需要准备一张小黄人的bmp就可以了。 我的由于是wps,不能支持那么多单元格。没有画完,你们可以在excel上试一下。 附上代码: Set objFso = CreateObject("Scripting.FileSystemObject")Rem Set objStream = objFso.OpenTextFile("D:\hinusDocs\vbs\tangwei.bmp", 1, True, -2)Set objStream = CreateObject("ADODB.Stream") objStream.Type = 1objStream.Mode = 3objStream.OpenobjStream.loadFromFile "C:\hinusDocs\vbs\tangwei.bmp"dim byte1, byte2, byte3, byte4byte1 = ascb(midb(objStream.Read(1), 1, 1))byte2 = ascb(midb(objStream.Read(1), 1, 1))if byte1 <> asc("B") or byte2 <> asc("M") then msgbox "error with file flag"end ifREM file lengthdim tmptmp = objStream.read(4)byte1 = ascb(midb(tmp, 1, 1))byte2 = ascb(midb(tmp, 2, 1))byte3 = ascb(midb(tmp, 3, 1))byte4 = ascb(midb(tmp, 4, 1))dim lengthlength = byte4 * 16777216 + byte3 * 65536 + byte2 * 256 + byte1REM tow zerotmp = objStream.read(4)for i = 1 to lenb(tmp) byte1 = ascb(midb(tmp, i, 1)) if byte1 <> 0 then msgbox "error with reserved" end ifnextREM offsettmp = objStream.read(4)byte1 = ascb(midb(tmp, 1, 1))byte2 = ascb(midb(tmp, 2, 1))byte3 = ascb(midb(tmp, 3, 1))byte4 = ascb(midb(tmp, 4, 1))dim offsetoffset = byte4 * 16777216 + byte3 * 65536 + byte2 * 256 + byte1dim biSizetmp = objStream.read(4)byte1 = ascb(midb(tmp, 1, 1))byte2 = ascb(midb(tmp, 2, 1))byte3 = ascb(midb(tmp, 3, 1))byte4 = ascb(midb(tmp, 4, 1))biSize = byte4 * 16777216 + byte3 * 65536 + byte2 * 256 + byte1dim biWidthtmp = objStream.read(4)byte1 = ascb(midb(tmp, 1, 1))byte2 = ascb(midb(tmp, 2, 1))byte3 = ascb(midb(tmp, 3, 1))byte4 = ascb(midb(tmp, 4, 1))biWidth = byte4 * 16777216 + byte3 * &H10000 + byte2 * &H100 + byte1dim biHeighttmp = objStream.read(4)byte1 = ascb(midb(tmp, 1, 1))byte2 = ascb(midb(tmp, 2, 1))byte3 = ascb(midb(tmp, 3, 1))byte4 = ascb(midb(tmp, 4, 1))biHeight = byte4 * 16777216 + byte3 * &H10000 + byte2 * &H100 + byte1rem biPlanestmp = objStream.read(2)byte1 = ascb(midb(tmp, 1, 1))byte2 = ascb(midb(tmp, 2, 1))if byte2 <> 0 or byte1 <> 1 then msgbox "error with biPlanes"end ifdim biBitCounttmp = objStream.read(2)byte1 = ascb(midb(tmp, 1, 1))byte2 = ascb(midb(tmp, 2, 1))biBitCount = byte2 * &H100 + byte1dim biCompressiontmp = objStream.read(4)byte1 = ascb(midb(tmp, 1, 1))byte2 = ascb(midb(tmp, 2, 1))byte3 = ascb(midb(tmp, 3, 1))byte4 = ascb(midb(tmp, 4, 1))biCompression = byte4 * &H1000000 + byte3 * &H10000 + byte2 * &H100 + byte1if biCompression <> 0 then msgbox "can not handle compressed bmp file"end ifdim biSizeImagetmp = objStream.read(4)byte1 = ascb(midb(tmp, 1, 1))byte2 = ascb(midb(tmp, 2, 1))byte3 = ascb(midb(tmp, 3, 1))byte4 = ascb(midb(tmp, 4, 1))biSizeImage = byte4 * &H1000000 + byte3 * &H10000 + byte2 * &H100 + byte1dim biXPelsPerMetertmp = objStream.read(4)byte1 = ascb(midb(tmp, 1, 1))byte2 = ascb(midb(tmp, 2, 1))byte3 = ascb(midb(tmp, 3, 1))byte4 = ascb(midb(tmp, 4, 1))biXPelsPerMeter = byte4 * &H1000000 + byte3 * &H10000 + byte2 * &H100 + byte1dim biYPelsPerMetertmp = objStream.read(4)byte1 = ascb(midb(tmp, 1, 1))byte2 = ascb(midb(tmp, 2, 1))byte3 = ascb(midb(tmp, 3, 1))byte4 = ascb(midb(tmp, 4, 1))biYPelsPerMeter = byte4 * &H1000000 + byte3 * &H10000 + byte2 * &H100 + byte1' pallete is not used when biBitCount == 24tmp = objStream.read(8)dim img, x, yimg = objStream.read()if biSizeImage <> lenb(img) then msgbox "error with image size"end ifdim oExcel,oWb,oSheet Set oExcel= CreateObject("Excel.Application") Set oWb = oExcel.Workbooks.Open("C:\hinusDocs\vbs\test.xls")Set oSheet = oWb.Sheets("Sheet1")for y = 1 to biHeight oSheet.Rows(y).RowHeight = 3nextfor x = 1 to biWidth oSheet.Columns(x).ColumnWidth = 0.3nextoExcel.Visible = Truedim index, color, remainderremainder = (biSizeImage - biWidth * biHeight * 3) / biHeightfor y = 0 to biHeight - 1 for x = 0 to biWidth - 1 index = (biHeight - 1 - y) * ((biWidth) * 3 + remainder) + x * 3 + 1 byte1 = ascb(midb(img, index, 1)) byte2 = ascb(midb(img, index + 1, 1)) byte3 = ascb(midb(img, index + 2, 1)) color = byte1 * &H10000& + byte2 * &H100& + byte3 oSheet.Cells.item(y+1, x+1).interior.color = color nextnextobjStream.close
在 C 盘新建目录hinusDocs/vbs/,然后存到这个目录下面的,保存成drawexcel.vbs,同一个目录下还得有女神的bmp文件,我们是照着这个bmp去画的。 然后新建一个空白的excel表,叫"test.xls",双击这个drawexcel.vbs运行就可以了。 |