Code: Select all
P := 1, T := "", styles := "", ranges := ""
xl := ComObjActive("excel.application")
sht := xl.Activesheet, wrkbk := xl.ActiveWorkbook
rng1 := "A1:N158", rng2 := "A158:I158"
for x,y in [rng1,rng2] ; include one or more ranges
{
wrkbk.PublishObjects.Add(4, A_Temp "\xl2html.htm", sht.name, y, 0).publish(1) ; xlSourceRange=4 xlHtmlStatic=0
fileread, html, % A_temp "\xl2html.htm"
htmlarr := strsplit(html,["<body>","</body>"])
styles .= htmlarr.1, ranges .= htmlarr.2 "<br>"
}
While V := xStr(styles,,"<style id","</style>",P,,,,0,0) ; H,,B,E,BO,,,,BT,ET
T .= V "`n"
style := xStr(styles,,"<html","<![endif]-->",,,,,0,0) . T
html := style "</head>`n`n<body>`n" . ranges . "</body></html>"
filedelete, % A_Temp "\xl2html.htm"
gui, margin, 0,0
gui, add, ActiveX, x0 y0 w1600 h600 vWB, HTMLfile
WB.write(html)
Gui, Show, , xl2gui
Return
xStr(ByRef H, C:=0, B:="", E:="",ByRef BO:=1, EO:="", BI:=1, EI:=1, BT:="", ET:="") {
Local L, LB, LE, P1, P2, Q, N:="", F:=0 ; xStr v0.97 by SKAN on D1AL/D343 @ tiny.cc/xstr
Return SubStr(H,!(ErrorLevel:=!((P1:=(L:=StrLen(H))?(LB:=StrLen(B))?(F:=InStr(H,B,C&1,BO,BI))?F+(BT=N?LB
:BT):0:(Q:=(BO=1&&BT>0?BT+1:BO>0?BO:L+BO))>1?Q:1:0)&&(P2:=P1?(LE:=StrLen(E))?(F:=InStr(H,E,C>>1,EO=N?(F
?F+LB:P1):EO,EI))?F+LE-(ET=N?LE:ET):0:EO=N?(ET>0?L-ET+1:L+1):P1+EO:0)>=P1))?P1:L+1,(BO:=Min(P2,L+1))-P1)
}