Thinkai's Blog

Autohotkey|Python|php|aardio|VOIP|IT 爱好者

WM_COPYDATA发送 进程间通信 AAuto 2839

作者为 发表

AAuto快手

import console;
import winex; 
SendMessage = ::User32.api("SendMessageA","int(int hwnd,int wMsg,int wParam,struct & lParam)")
COPYDATASTRUCT = class{
int dwData;
int cbData;
str lpData;
}

var hwnd = winex.find("AutoHotkeyGUI","AHK_Monitor");
var a = "ab为cd"
console.log(a,#a);
var msg = COPYDATASTRUCT()
msg.dwData = 3353;
msg.cbData = #a;
msg.lpData =  a;
SendMessage(hwnd,0x4a,0x0,msg)


console.pause(true);


Excel数据拆分发邮件 Autohotkey 4370

作者为 发表

Autohotkey

;Thinkai@2015-10-27

;本脚本需要安装office 2007 如果需要在仅有2003条件下运行,请替换323行注释掉的连接字串并替换.xlsx后缀
Gui, main:Add, button, x0 y0 w100 h20 gaddtab, 添加表格数据源
gui, main:add, Button, x100 y0 w100 h20 gsetto, 设置收件人信息
gui, main:add, Button, x200 y0 w100 h20 gsetfrom, 设置发件人信息
gui, main:add, Button, x300 y0 w100 h20 gsend, 开始发送
gui, main:add, Button, x400 y0 w100 h20 grl, 重新开始
;gui, main:add, text, x0 y20 w100 h20, 发件人(可选)
;gui, main:add, Edit, x100 y20 w500 h20 vfrom
gui, main:add, text, x0 y40 w100 h20, 标题前缀
gui, main:add, Edit, x100 y40 w500 h20 vtitle
Gui, main:add,text, x0 y60 w600 h20, 正文 可用插入[delimiter]替换拆分字段信息
gui, main:add, Edit, x0 y80 w600 h100 vcontent
gui, main:add, Progress, x0 y180 w600 h20 vprg,
Gui, main:Add, ListView, x0 y200 w600 h300 vlv, 文件|Sheet|拆分依据字段|输出文件名前缀|目标Sheet
Gui, main:Add, StatusBar, , 等待用户操作
Gui, main:show, , Excel数据拆分发邮件
Gui, main:Default
;调整、初始化信息
LV_ModifyCol(1,150)
LV_ModifyCol(2,120)
LV_ModifyCol(3,120)
LV_ModifyCol(4,120)
LV_ModifyCol(5,120)
SB_SetParts(400,200)
source := [] ;数据源数组
mailconfig:=[] ;发件人信息数组
IfExist config.ini ;读取发件人配置
{
	IniRead, setfrom_from, config.ini, from, from
	IniRead, setfrom_bcc, config.ini, from, bcc
	IniRead, setfrom_smtp, config.ini, from, smtp
	IniRead, setfrom_account, config.ini, from, account
	IniRead, setfrom_pass, config.ini, from, pass
	mailconfig.from:=setfrom_from,mailconfig.bcc:=setfrom_bcc,mailconfig.smtp:=setfrom_smtp,mailconfig.account:=setfrom_account,mailconfig.pass:=setfrom_pass
}
to_obj := []
IfExist, to.txt ;读取收件人名录
{
	FileRead, str, to.txt
	to_obj := getto(str)
}
return

addtab: ;添加数据源
FileSelectFile, file, , , 选择一个表格, Excel文件(*.xls;*.xlsx)
IfExist % file
{
	SplitPath, file, , , , name ;获取文件名
	source.insert({"name":name,"file":file,"sheets":{}})
	SB_SetText("读取文件:" file)
	idx := source.maxindex()
	source[idx].db := new exceldb() ;创建excel adodb连接,获取数据表信息
	source[idx].db.open(file)
	SB_SetText("读取文件:" file " 完毕!")
	sheet := source[idx].db.GetTableInfo()
	for k,v in sheet ;弹出若干个向导页设置数据源
	{
		guide_fields := v
		SB_SetText("等待用户设置数据源")
		isguideok := false
		Gui, guide:Destroy
		Gui, guide:add, text, x0 y0 w100 h20, % "文件:"
		Gui, guide:add, text, x0 y20 w100 h20, % "Sheet:"
		Gui, guide:add, text, x100 y0 w300 h20, % guide_file:=file
		Gui, guide:add, text, x100 y20 w300 h20, % guide_sheet:=k
		f :="" ;,guide_sql:="CREATE TABLE [" k "] (" ;创建表语句 已废弃
		for x,y in v
		{
			f .= f ? "|" y : y
			;guide_sql .= y " TEXT,"
		}
		;StringTrimRight, guide_sql, guide_sql, 1
		;guide_sql .= ")"
		Gui, guide:add, text, x0 y40 w100 h20, 拆分依据字段:
		Gui, guide:add, DropDownList, x100 y40 w300 vguide_ddl, % f
		Gui, guide:add, text, x0 y60 w100 h20, 输出文件名前缀:
		Gui, guide:add, Edit, x100 y60 w300 h20 vguide_prefix, % name
		Gui, guide:add, text, x0 y80 w100 h20, 目标Sheet:
		Gui, guide:add, Edit, x100 y80 w300 h20 vguide_dstsheet, % k
		Gui, guide:add, Button, x0 y100 w200 h20 gconfirm, 确认
		Gui, guide:add, Button, x200 y100 w200 h20 gjump, 跳过
		Gui, guide:Show, , % "数据源导入向导——" name
		while(!isguideok)
			Sleep, 100
		Gui, guide:Destroy
		SB_SetText("数据源设置完毕")
	}
	;source[idx].db.close() ;不关闭连接。特别是对于一些大的07文件,在后续拆分情况下避免消耗无谓时间

}
return

rl: ;重载
Reload

confirm: ;向导确认
Gui, guide:Submit, NoHide
if !guide_ddl
{
	MsgBox, 4112, 错误, 拆分依据字段不能为空!
	return
}
Gui, main:Default
LV_Add("",guide_file,guide_sheet,guide_ddl,guide_prefix,guide_dstsheet)
source[idx]["sheets"].insert({"fields":guide_fields,"sheet":guide_sheet,"delimiter":guide_ddl,"prefix":guide_prefix,"dstsheet":guide_dstsheet}) ;,"createsql":guide_sql
isguideok := true
return

jump: ;向导跳过
isguideok := true
return

setto: ;设置收件人
IfExist, to.txt
	FileRead, to, to.txt
Gui, setto:Destroy
Gui, setto:Add, text, x0 y0 w600 h40, 在下方修改联系人信息。可从excel中粘贴过来,左边是拆分依据字段,右边联系人邮箱,多个用`"`,`"分隔`n例如:某某部门	xxx<xxx@xxx.com>`,`"xxx`"<xxx@xxx.com> (制表符分隔)
Gui, setto:Add, Edit, x0 y40 w600 h400 vsetto_to, % to
Gui, setto:Add, Button, x0 y440 w600 h20 gsetto_ok, 确定
Gui, setto:Show, , 设置收件人信息
return

setto_ok: ;设置收件人完毕
GuiControlGet, setto_to
FileDelete, to.txt
FileAppend, % setto_to, to.txt
to_obj := getto(setto_to)
Gui, setto:Destroy
return

setfrom: ;设置发件人
IfExist config.ini
{
	IniRead, setfrom_from, config.ini, from, from
	IniRead, setfrom_bcc, config.ini, from, bcc
	IniRead, setfrom_smtp, config.ini, from, smtp
	IniRead, setfrom_account, config.ini, from, account
	IniRead, setfrom_pass, config.ini, from, pass

}
Gui, setfrom:Destroy
Gui, setfrom:add, text, x0 y0 w100 h20, 默认发件人*
Gui, setfrom:add, Edit, x100 y0 w300 h20 vsetfrom_from, % setfrom_from ? setfrom_from : "某某<xxx@xxx.com>"
Gui, setfrom:add, text, x0 y20 w100 h20, 默认暗送人
Gui, setfrom:add, Edit, x100 y20 w300 h20 vsetfrom_bcc, % setfrom_bcc ? setfrom_bcc : "某某<xxx@xxx.com>"
Gui, setfrom:add, text, x0 y40 w100 h20, 发件邮箱smtp*
Gui, setfrom:add, Edit, x100 y40 w300 h20 vsetfrom_smtp, % setfrom_smtp ? setfrom_smtp : "smtp.xxx.com"
Gui, setfrom:add, text, x0 y60 w100 h20, 发件邮箱账号*
Gui, setfrom:add, Edit, x100 y60 w300 h20 vsetfrom_account, % setfrom_account ? setfrom_account : "xxx@xxx.com"
Gui, setfrom:add, text, x0 y80 w100 h20, 发件邮箱密码*
Gui, setfrom:add, Edit, x100 y80 w300 h20 vsetfrom_pass, % setfrom_pass
Gui, setfrom:add, Button ,x0 y100 w400 h20 gsetfrom_ok, 确定
Gui, setfrom:Show, , 设置发件人信息
return

setfrom_ok: ;设置发件人完毕
Gui, setfrom:Submit, NoHide
Gui, setfrom:Destroy
IniWrite, % setfrom_from, config.ini, from, from
IniWrite, % setfrom_bcc, config.ini, from, bcc
IniWrite, % setfrom_smtp, config.ini, from, smtp
IniWrite, % setfrom_account, config.ini, from, account
IniWrite, % setfrom_pass, config.ini, from, pass
mailconfig.from:=setfrom_from,mailconfig.bcc:=setfrom_bcc,mailconfig.smtp:=setfrom_smtp,mailconfig.account:=setfrom_account,mailconfig.pass:=setfrom_pass
return

send: ;开始拆分发送
Gui, main:Submit, NoHide
SB_SetText("检查发件人信息")
if ((!mailconfig.from && !from) || !mailconfig.smtp || !mailconfig.account || !mailconfig.pass)
{
	MsgBox, 4112, 错误, 发件人信息未配置完整,请设置!
	return
}
GuiControl, main:, prg, 2
SB_SetText("检查收件人信息")
if (to_obj.maxindex()=0)
{
	MsgBox, 4112, 错误, 收件人信息未配置,请设置!
	return
}
GuiControl, main:, prg, 3
SB_SetText("检查标题信息")
if !title
{
	MsgBox, 4112, 错误, 标题未填写,请填写!
	return
}
GuiControl, main:, prg, 4
SB_SetText("创建临时目录")
FileCreateDir, %A_ScriptDir%tmp
FileDelete, %A_ScriptDir%tmp*.*
GuiControl, main:, prg, 5
SB_SetText("创建模板文件")
template := []
for a,b in source ;汇总要创建哪些模板文件 哪些sheet
{
	sheets := b.sheets
	for c,d in sheets
	{
		if !IsObject(template[d.prefix])
			template[d.prefix] := []
		if !template[d.prefix][d.dstsheet]
			template[d.prefix][d.dstsheet] := {"file":b.file,"prefix":d.prefix,"fields":d.fields}
	}
}
GuiControl, main:, prg, 8
for e,f in template ;创建模板文件
{
	file := A_ScriptDir "tmp" e ".xlsx"
	g := new excel() ;新建Excel对象
	g.open(file)
	for h,i in f
	{
		if A_Index > 3 ;如果超出默认的3个sheet
			g.conn.ActiveWorkbook.Sheets.Add
		g.conn.ActiveWorkbook.Sheets(A_index).Name := h ;重命名
		g.setfields(A_index,i.fields) ;插入字段
		g.save() ;保存
	}
	g.close()
}
GuiControl, main:, prg, 15
attach := []
SB_SetText("输出Excel")
for source_index,source_value in source ;遍历数据源
{
	SB_SetText(source_value.name)

	sheets := source_value.sheets ;遍历需要拆分的sheet
	if 	(source_value.sheets.maxindex() > 0)
	{
		for sheet_index,sheet_value in sheets
		{
			SB_SetText(source_value.name "`t "sheet_value.sheet)
			for delimiter in to_obj ;按拆分字段逐个拆分
			{
				;定义变量
				if !IsObject(attach[delimiter])
					attach[delimiter] := []
				tmp_file := A_ScriptDir "tmp" guide_prefix "_" delimiter ".xlsx"
				template_file := A_ScriptDir "tmp" guide_prefix ".xlsx"
				FileCopy, % template_file, % tmp_file, 1
				attach[delimiter].insert(tmp_file)
				SB_SetText(delimiter,2)
				tmp_result := source_value.db.GetTable("SELECT * FROM [" sheet_value.sheet "$] WHERE [" sheet_value.delimiter "]='" delimiter "';") ;读取拆分信息到数组
				tmp_excel := new exceldb()
				tmp_excel.open(tmp_file)
				tmp_excel.conn.BeginTrans()
				for row,vaules in tmp_result
				{
					tmp_str := ""
					for k,v in vaules
						tmp_str .= tmp_str ? ",'" v "'" : "'" v "'"
					tmp_excel.conn.Execute("INSERT INTO [" sheet_value.dstsheet "$] VALUES (" tmp_str ")") ;插入语句
				}
				tmp_excel.conn.CommitTrans()
				tmp_excel.close()
			}
		}
	}
	source_value.db.close()
}
GuiControl, main:, prg, 50

SB_SetText("发送邮件")
for delimiter,attaches in attach
{
	tmp_title := title "_" delimiter
	tmp_content := RegExReplace(content,"[delimiter]",delimiter)
	tmp_mail := to_obj[delimiter]
	SB_SetText("发送邮件:" tmp_title,2)
	SB_SetText(delimiter,2)
	Mail("",tmp_mail,tmp_title,tmp_content,attaches*)
}
GuiControl, main:, prg, 100
SB_SetText("发送完毕")

return

settoGuiClose:
Gui, setto:Destroy
return

setfromGuiClose:
Gui, setfrom:Destroy
return

guideGuiClose:
return

mainGuiClose:
ExitApp

getto(str){
	o := []
	Loop, Parse, str, `n, `r
	{
		IfInString, A_LoopField, `t
		{
			t := StrSplit(A_LoopField,"`t")
			o[t[1]] := t[2]
		}
	}
	return o
}

class exceldb
{
	;static conn

	__New() ;新建
	{
	this.conn:= ComObjCreate("ADODB.connection") ;初始化COM
	}

	open(file) ;打开文件
	{
		IfExist % file
			this.conn.Open("Provider=Microsoft.Ace.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" file) ;打开连接
			;this.conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=Yes';Data Source=" file) ;打开连接 2003方式
	}

	close() ;关闭文件
	{
		this.conn.Close()
	}


	GetTableInfo() ;获取所有Sheet及字段信息
	{
		;通过OpenSchema方法获取表信息
		rs := this.conn.OpenSchema(20) ;SchemaEnum 参考 http://www.w3school.com.cn/ado/app_schemaenum.asp
		t := []
		rs.MoveFirst()
		while !rs.EOF
		{
			t_name := RegExReplace(rs.("TABLE_NAME").value,"$$","")
			q := this.conn.Execute("select top 1 * from [" t_name "$]")
			if (q.Fields(0).Name="F1" && q.Fields.Count=1) ;排除空表格
			{
				rs.MoveNext()
				continue
			}
			t[t_name] := []
			for field in q.Fields  ;获取按顺序排列的字段
				t[t_name].insert(field.Name)
			q.close()
			rs.MoveNext()
		}
		return t
	}

	GetTable(sql)
	{
		t := []
		query := this.conn.Execute(sql)
		if RegExMatch(sql,"i)^select*")
		{
			fetchedArray := query.GetRows() ;取出数据(二维数组)
			colSize := fetchedArray.MaxIndex(1) + 1 ;列最大值 tips:从0开始 所以要+1
			rowSize := fetchedArray.MaxIndex(2) + 1 ;行最大值 tips:从0开始 所以要+1
			loop, % rowSize
			{
				i := (y := A_index) - 1
				t[y] := []
				loop, % colSize
				{
					j := (x := A_index) - 1
					t[y][x] := fetchedArray[j,i] ;取出二维数组内值
				}
			}
			query.Close()
			return t
		}
	}
}


class excel
{
    ;static conn

    __New() ;新建
    {
    this.conn:= ComObjCreate("Excel.Application")
    this.conn.Visible := false	;false
    }

    open(file) ;打开文件
    {
        IfExist % file
            this.conn.Workbooks.Open(file)
		else
		{
			this.conn.Workbooks.Add
			this.conn.ActiveWorkbook.SaveAs(file)
		}
    }

    close() ;关闭文件
    {
        this.conn.Workbooks.close()
    }


    sheets() ;获取所有Sheet
    {
        s := []
        loop % this.conn.ActiveWorkbook.Sheets.Count
            s.insert(this.conn.ActiveWorkbook.Sheets(A_index).Name)
        return s
    }

    fields(sheet) ;获取指定sheet的字段 sheet为id或者具体名称
    {
        c := []

        loop % this.conn.ActiveWorkbook.Sheets(sheet).Columns.Count
        {
            try
            {
                x := this.conn.ActiveWorkbook.Sheets(sheet).Cells(1,A_index).Value
                if !x
                    break
                c.insert(x)
            }
            catch e
                break
        }
        return c

        /*
        col_id := ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
        loop % this.conn.ActiveWorkbook.Sheets(sheet).Columns.Count
        {
            col := col_id[floor(A_index/26)] col_id[mod(A_index,26)]
            try
            {
                x:=excel.ActiveWorkbook.Sheets(sheet).Range(col "1").Value
                if !x
                    break
                colname.insert(x)
            }
            catch e
                break
        }
        */
    }

    setfields(sheet,fields) ;设置字段 即第一列信息
    {
        return this.insertrow(sheet,1,fields)
    }

    setformat(sheet,range,format) ;设置某一区域的单元格格式
    {
        this.conn.ActiveWorkbook.Sheets(sheet).Range(range).NumberFormat := format
    }

    insertrow(sheet,rowid,values) ;插入一列
    {
    for k,v in values
        this.conn.ActiveWorkbook.Sheets(sheet).Cells(rowid,A_index).Value := v
    }

	save()
	{
		this.conn.ActiveWorkbook.Save()
	}
}

;发邮件函数 参数 来自,发给,主题,html正文,附件若干
Mail(from,to,subject,content,attach*){
global mailconfig
NameSpace := "http://schemas.microsoft.com/cdo/configuration/"
Email := ComObjCreate("CDO.Message")
Email.From := mailconfig.from
Email.To := to
if mailconfig.bcc
		Email.Bcc := mailconfig.bcc
Email.Subject := subject
;Email.Htmlbody := content
Email.Textbody := content
for k,v in attach
{
	IfExist, % v
		Email.AddAttachment(v)
}
Email.Configuration.Fields.Item(NameSpace "sendusing") := 2
Email.Configuration.Fields.Item(NameSpace "smtpserver") := mailconfig.smtp  ;SMTP服务器地址
Email.Configuration.Fields.Item(NameSpace "smtpserverport") := 25
Email.Configuration.Fields.Item(NameSpace "smtpauthenticate") := 1
Email.Configuration.Fields.Item(NameSpace "sendusername") := mailconfig.account  ;邮箱账号
Email.Configuration.Fields.Item(NameSpace "sendpassword") := mailconfig.pass  ;邮箱密码
Email.Configuration.Fields.update
Email.Send
}


密码生成工具 MD5 Autohotkey 4783

作者为 发表

Autohotkey

gui, add, text, x0 y0 w100 h20, 项目名
gui, add, edit, x100 y0 w200 h20 vname
gui, add, text, x0 y20 w100 h20, 账户
gui, add, edit, x100 y20 w200 h20 vaccount
Gui, add, Checkbox, x0 y40 w300 h20 vlog, 记录到数据库
gui, add, edit, x0 y60 w300 h20 vpass
Gui, Add, Button, x0 y80 w300 h20 ggen, 生成密码
Gui, Show, , Thinkai的密码生成器
return

gen:
Gui, Submit, NoHide
md5 := MD5(MD5(name) "@xx@" account) ;此处为算法 32位MD5 可以自己改
b:=""
loop 14 ;此处做单数位大写处理 前十四位
{
	c := SubStr(md5,A_index,1)
	if (mod(A_index,2)=1)
		StringUpper, c, c
	b .= c
}
b .= "++" ;凑成16位 部分限制14位的比如百度就可以酌情复制
GuiControl, , pass, % Clipboard := b ;更新到结果框并复制到剪切板
if log ;此处通过途径记录到你的库里 或者写到文件里
    URLDownloadToFile, http://xx.com/reg.php?name=%name%&account=%account%, %A_Temp%\xx.tmp
return

GuiClose:
ExitApp

MD5(string, encoding = "UTF-8")
{
    return CalcStringHash(string, 0x8003, encoding)
}

CalcStringHash(string, algid, encoding = "UTF-8", byref hash = 0, byref hashlength = 0)
{
    chrlength := (encoding = "CP1200" || encoding = "UTF-16") ? 2 : 1
    length := (StrPut(string, encoding) - 1) * chrlength
    VarSetCapacity(data, length, 0)
    StrPut(string, &data, floor(length / chrlength), encoding)
    return CalcAddrHash(&data, length, algid, hash, hashlength)
}

CalcAddrHash(addr, length, algid, byref hash = 0, byref hashlength = 0)
{
    static h := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f"]
    static b := h.minIndex()
    hProv := hHash := o := ""
    if (DllCall("advapi32\CryptAcquireContext", "Ptr*", hProv, "Ptr", 0, "Ptr", 0, "UInt", 24, "UInt", 0xf0000000))
    {
        if (DllCall("advapi32\CryptCreateHash", "Ptr", hProv, "UInt", algid, "UInt", 0, "UInt", 0, "Ptr*", hHash))
        {
            if (DllCall("advapi32\CryptHashData", "Ptr", hHash, "Ptr", addr, "UInt", length, "UInt", 0))
            {
                if (DllCall("advapi32\CryptGetHashParam", "Ptr", hHash, "UInt", 2, "Ptr", 0, "UInt*", hashlength, "UInt", 0))
                {
                    VarSetCapacity(hash, hashlength, 0)
                    if (DllCall("advapi32\CryptGetHashParam", "Ptr", hHash, "UInt", 2, "Ptr", &hash, "UInt*", hashlength, "UInt", 0))
                    {
                        loop % hashlength
                        {
                            v := NumGet(hash, A_Index - 1, "UChar")
                            o .= h[(v >> 4) + b] h[(v & 0xf) + b]
                        }
                    }
                }
            }
            DllCall("advapi32\CryptDestroyHash", "Ptr", hHash)
        }
        DllCall("advapi32\CryptReleaseContext", "Ptr", hProv, "UInt", 0)
    }
    return o
}


这是一个拆分excel发邮件的半成品,因为换API方式所以记录下。

Gui, main:Add, button, x0 y0 w100 h20 gaddtab, 添加表格数据源
gui, main:add, Button, x100 y0 w100 h20, 设置收件人信息
gui, main:add, Button, x200 y0 w100 h20, 设置发件人信息
gui, main:add, Button, x300 y0 w100 h20, 开始发送
gui, main:add, Progress, x0 y20 w600 h20 vprg, 10
Gui, main:Add, ListView, x0 y40 w600 h300 vlv, 文件|Sheet|拆分依据字段|输出文件名前缀|目标Sheet
Gui, main:Add, StatusBar, , 等待用户操作
Gui, main:show, , Excel数据拆分发邮件
Gui, main:Default
LV_ModifyCol(1,150)
LV_ModifyCol(2,120)
LV_ModifyCol(3,120)
LV_ModifyCol(4,120)
LV_ModifyCol(5,120)
SB_SetParts(400,200)

return

addtab:
FileSelectFile, file, , , 选择一个表格, Excel文件(*.xls;*.xlsx)
IfExist % file
{
	SplitPath, file, , , , name
	SB_SetText("读取文件:" file)
	a := new excel()
	a.open(file)
	sheet := a.sheets()
	for k,v in sheet
	{
		SB_SetText("等待用户设置数据源")
		isguideok := false
		Gui, guide:Destroy
		Gui, guide:add, text, x0 y0 w100 h20, % "文件:"
		Gui, guide:add, text, x0 y20 w100 h20, % "Sheet:"
		Gui, guide:add, text, x100 y0 w300 h20, % guidefile:=file
		Gui, guide:add, text, x100 y20 w300 h20, % guidesheet:=v
		f =
		field := a.fields(A_index)
		for x,y in field
			f .= f ? "|" y : y
		Gui, guide:add, text, x0 y40 w100 h20, 拆分依据字段:
		Gui, guide:add, DropDownList, x100 y40 w300 vguideddl, % f
		Gui, guide:add, text, x0 y60 w100 h20, 输出文件名前缀:
		Gui, guide:add, Edit, x100 y60 w300 h20 vguideprefix, % name
		Gui, guide:add, text, x0 y80 w100 h20, 目标Sheet:
		Gui, guide:add, Edit, x100 y80 w300 h20 vguidedstsheet, % v
		Gui, guide:add, Button, x0 y100 w200 h20 gconfirm, 确认
		Gui, guide:add, Button, x200 y100 w200 h20 gjump, 跳过
		Gui, guide:Show, , % "数据源导入向导——" name
		while(!isguideok)
			Sleep, 100
		Gui, guide:Destroy
		SB_SetText("数据源设置完毕")
	}
	a.close()

}
return

confirm:
Gui, guide:Submit, NoHide
if !guideddl
{
	MsgBox, 4112, 错误, 拆分依据字段不能为空!
	return
}
Gui, main:Default
LV_Add("",guidefile,guidesheet,guideddl,guideprefix,guidedstsheet)

isguideok := true
return

jump:
isguideok := true
return

guideGuiClose:
return

mainGuiClose:
ExitApp

class excel
{
	;static conn

	__New() ;新建
	{
	this.conn:= ComObjCreate("Excel.Application")
	this.conn.Visible := false ;false
	}

	open(file) ;打开文件
	{
		IfExist % file
			this.conn.Workbooks.Open(file)
	}

	close() ;关闭文件
	{
		this.conn.Workbooks.close()
	}


	sheets() ;获取所有Sheet
	{
		s := []
		loop % this.conn.ActiveWorkbook.Sheets.Count
			s.insert(this.conn.ActiveWorkbook.Sheets(A_index).Name)
		return s
	}

	fields(sheet) ;获取指定sheet的字段 sheet为id或者具体名称
	{
		c := []

		loop % this.conn.ActiveWorkbook.Sheets(sheet).Columns.Count
		{
			try
			{
				x := this.conn.ActiveWorkbook.Sheets(sheet).Cells(1,A_index).Value
				if !x
					break
				c.insert(x)
			}
			catch e
				break
		}
		return c

		/*
		col_id := ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
		loop % this.conn.ActiveWorkbook.Sheets(sheet).Columns.Count
		{
			col := col_id[floor(A_index/26)] col_id[mod(A_index,26)]
			try
			{
				x:=excel.ActiveWorkbook.Sheets(sheet).Range(col "1").Value
				if !x
					break
				colname.insert(x)
			}
			catch e
				break
		}
		*/
	}

	setfields(sheet,fields) ;设置字段 即第一列信息
	{
		return this.insertrow(sheet,1,fields)
	}

	setformat(sheet,range,format) ;设置某一区域的单元格格式
	{
		this.conn.ActiveWorkbook.Sheets(sheet).Range(range).NumberFormat := format
	}

	insertrow(sheet,rowid,values) ;插入一列
	{
	for k,v in values
		this.conn.ActiveWorkbook.Sheets(sheet).Cells(rowid,A_index).Value := v
	}
}


输出excel数据到GUI 获取excel所有Sheet及字段 Autohotkey 5731

作者为 发表

Autohotkey

;Thinkai@2015-10-25
Gui, Add, Tab, x0 y0 w800 h500 vtab
Gui, Show, , 输出excel数据到GUI
FileSelectFile, file, , , 选择一个表格, Excel文件(*.xls;*.xlsx)
IfNotExist % file
    ExitApp
conn := ComObjCreate("ADODB.connection") ;初始化COM
conn.Open("Provider=Microsoft.Ace.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" file) ;打开连接
;conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=Yes';Data Source=" file) ;打开连接 2003方式
;通过OpenSchema方法获取表信息
rs := conn.OpenSchema(20) ;SchemaEnum 参考 http://www.w3school.com.cn/ado/app_schemaenum.asp
table_info := []
rs.MoveFirst()
while !rs.EOF ;有效Sheet
{
	t_name := RegExReplace(rs.("TABLE_NAME").value,"\$$","")
	q := conn.Execute("select top 1 * from [" t_name "$]")
	if (q.Fields(0).Name="F1" && q.Fields.Count=1) ;排除空表格
	{
		rs.MoveNext()
		continue
	}
	table_info[t_name] := []
	for field in q.Fields  ;获取按顺序排列的字段
		table_info[t_name].insert(field.Name)
	q.close()
	rs.MoveNext()
}
;生成Listview
for t,c in table_info
{
	;创建tab及listview
	GuiControl, , tab, % t
	Gui, Tab, % A_index
	cols =
	for k,v in c
		cols .= cols ? "|" v : v
	Gui, Add, ListView, % "x10 y30 w780 h460 vlv" A_Index, % cols
	Gui, ListView, % "lv" A_Index

	;获取表格数据
	data := GetTable("select * from [" t "$]")
	for k,v in data
		LV_Add("",v*)

	LV_ModifyCol() ;自动调整列宽
}
rs.close()
conn.close()
return

GuiClose:

ExitApp

GetTable(sql){ ;Adodb通用的获取数据数组的函数
    global conn
    t := []
    query := conn.Execute(sql)
    fetchedArray := query.GetRows() ;取出数据(二维数组)
    colSize := fetchedArray.MaxIndex(1) + 1 ;列最大值 tips:从0开始 所以要+1
    rowSize := fetchedArray.MaxIndex(2) + 1 ;行最大值 tips:从0开始 所以要+1
    loop, % rowSize
    {
        i := (y := A_index) - 1
        t[y] := []
        loop, % colSize
        {
            j := (x := A_index) - 1
            t[y][x] := fetchedArray[j,i] ;取出二维数组内值
        }
    }
	query.close()
    return t
}


QQ恶搞小黄脸表情包2825个 6771

作者为 发表

图片

小黄脸微型恶搞_893个:


小黄脸升级恶搞_529个:


旧小黄脸恶搞_1403个:


下载

子窗口不退出 AAuto 3758

作者为 发表

AAuto快手

import win.ui;
..ShowWindow = ::User32.api("ShowWindow","int(int hwnd,int nCmdShow)")
/*DSG{{*/
var winform = ..win.form(text="MainForm";right=269;bottom=133)
winform.add(
button={cls="button";text="子窗口";left=61;top=39;right=200;bottom=86;z=1}
)
/*}}*/

var subform = ..win.form(text="SubForm";right=200;bottom=100)
subform.add(
)

subform.onClose = function(hwnd,message,wParam,lParam){
ShowWindow(subform.hwnd,0x0) //显示
return 0
}

winform.button.oncommand = function(id,event){
	//winform.msgbox( winform.button.text );
	ShowWindow(subform.hwnd,0x5) //隐藏
	return 0
}

winform.show()
win.loopMessage();


采集奇书网qisuu小说到数据库 Autohotkey 7583

作者为 发表

Autohotkey

;预配置项
url_l = http://www.qisuu.com/soft/sort01/index_
id = 2 ;初始页码
maxid = 255 ;最大页码
url_r = .html
site =  http://www.qisuu.com
kind = 玄幻奇幻 ;分类 1玄幻奇幻_289 2武侠仙侠_211 3女频言情_792 4现代都市_255 5历史军事_141 6游戏竞技_99 7科幻灵异_154

#NoEnv
OnExit, exit
;初始化连接数据库 以便反复查询
DBFileName := A_ScriptDir . "qisuu.db"
global DB
DB := new SQLiteDB
If !DB.OpenDB(DBFileName) {
   MsgBox, 16, SQLite错误, % "消息:`t" . DB.ErrorMsg . "`n代码:`t" . DB.ErrorCode
   ExitApp
}
;首先检查初始化
if !IsObject(Query("select 1 from sqlite_master where name='novel'")) ;检查novel表
	Exec("CREATE TABLE ""novel"" ( ""kind"" TEXT(255), ""name"" TEXT(255), ""author"" TEXT(255), ""size"" TEXT(255), ""class"" TEXT(255), ""url"" TEXT(255), ""image"" TEXT(255), ""description"" TEXT(255), ""download"" TEXT(255), ""creat_date"" TEXT(50), ""id"" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)")

Loop % maxid-id
{
	list := URLDownloadToVar(url_l id url_r,"gb2312") ;抓取小说列表
	a := StrSplit(list,"`n","`r") ;分割行为数组
	a_id = 465 ;直接跳到正文
	Loop
	{
		a_id++
		if (a_id>a.maxindex())
			break
		;抓取文章信息
		if (RegExMatch(a[a_id],"s+<[^>]*>作者:([^<]*)<[^>]*>大小:([^<]*)<[^>]*>等级:<em class=""lstar(d)""><[^>]*><[^>]*>更新:([^<]*)<[^>]*>",b) || RegExMatch(a[a_id],"s+<[^>]*>作者:<[^>]*>([^<]*)<[^>]*><[^>]*>大小:([^<]*)<[^>]*>等级:<em class=""lstar(d)""><[^>]*><[^>]*>更新:([^<]*)<[^>]*>",b))
		{
			author:=b1,size:=b2,class=b3,creat_date:=b4
			a_id++
			if (RegExMatch(a[a_id],"s+<a href=""([^""]*)""><img src=""([^""]*)""><[^>]*><[^>]*>([^<]*)<[^>]*><[^>]*><[^>]*>",c) || RegExMatch(a[a_id],"s+<a href=""([^""]*)""><img src=""([^""]*)"">([^<]*)<[^>]*>",c))
			{
				url:=site c1,image:=site c2,name:=c3
				a_id++
				RegExMatch(a[a_id],"s+<div class=""u"">([^<]*)</div>",f)
				description := f1
				page := URLDownloadToVar(url,"gb2312") ;获取详细页的下载地址
				d := StrSplit(page,"`n","`r")
				Loop % d.maxindex()
				{
					if RegExMatch(d[A_Index],"s+<a class=""downButton"" href='([^']*)' title=""[^""]*"">RAR格式下载</a>",e)
					{
						download:=e1
						ToolTip % id "页:" name
						 Exec("INSERT INTO ""novel"" (""kind"", ""name"", ""author"", ""size"", ""class"", ""url"", ""image"", ""description"", ""download"", ""creat_date"") VALUES ('" kind "','" name "','" author "','" size "','" class "','" url "','" image "','" description "','" download "','" creat_date "')") ;插入数据库
						break
					}
				}
			}
		}
	}
id++
}
MsgBox, Ok

exit:
DB.CloseDB()
DB =
ExitApp

获取完整版

改console.varDump为字符串输出 AAuto 2527

作者为 发表

AAuto快手

varDump = function(...){
    var args = {...};
    var str = '';
    var b,e = ..table.range(args);
    for(i=b;e){
    	var arg = args[i];
    	var t = type(arg);
    	str = string.concat(str,"参数位置:",i,'
',"数据类型:",t,'
');
    	if( t != type.table ){
    		str = string.concat(str,"变量值:",tostring(arg),'
');
    	}
    	else { 
    		str = string.concat(str,"变量值: {",'
');	
    		var logged = { _struct = 1 };
    		for k,v in ..table.eachName(arg){
    			logged[k] = true;
    			str = string.concat(str,'    ', k,' = ',tostring(v) ,'
');   
    		}
    		for(i=1;#arg;1){
    			logged[i] = true; 
    			str = string.concat(str,'    [', i,'] = ',tostring(arg[i]) ,'
');
    		}
    		for(k,v in arg){
    			if( !logged[k] ){
    				str = string.concat(str,'    [', tostring(k),'] = ',tostring(v) ,'
');
    			} 
    		}
            str = string.concat(str,'}','
');
            if(#arg){
            	str = string.concat(str,"序列数组长度:",#arg,'
');
            }
            if(arg._struct){
            	try{
            		str = string.concat(str,L("结构体大小:"),..raw.sizeof(arg),'
');
            	}
            	catch(e){
            		str = string.concat(str,"结构体大小:未知(包含动态数组)",'
');
            	}
            }
    	}  
    } 
return str
}


文本转语音(百度在线tts) 转自Q群70517368 AAuto 3429

作者为 发表

AAuto快手

import win.ui;
import win.mm
/*DSG{{*/
mainForm = ..win.form(text="AAuto Form";right=233;bottom=323)
mainForm.add(
button={cls="button";text="转语音";left=35;top=278;right=97;bottom=310;z=2};
button2={cls="button";text="朗读";left=119;top=278;right=181;bottom=310;z=3};
edit={cls="edit";left=5;top=8;right=227;bottom=268;autohscroll=false;edge=1;multiline=1;vscroll=1;z=1}
)
/*}}*/

mainForm.button2.oncommand = function(id,event){
	win.mm.playMp3("/temp.mp3")
}

mainForm.button.oncommand = function(id,event){
	if(mainForm.edit.text = "") return ; 
	mainForm.button.disabled = true
	var bdmp3 = win.invoke(text2audio,mainForm.edit.text)
	if(bdmp3){
		string.save("/temp.mp3",bdmp3 )
		win.msgbox("转语音成功")
	}else {
		win.msgbox("转语音失败")
	}
	mainForm.button.disabled = false
}
text2audio = function(ctext){
	import inet.whttp;
	import inet.url
	var whttp = inet.whttp()
	ctext = inet.url.encode(inet.url.encode(ctext,true),true)
	whttp.beginRequest("http://tts.baidu.com/text2audio?idx=1&tex="+ctext+"&cuid=baidu_speech_demo&cod=2&lan=zh&ctp=1&pdt=1&spd=5&per=0&vol=5&pit=5")
	whttp.send()
	var ctype = whttp.readHeader("Content-type")
	var bdmp3 = whttp.readAll()
	whttp.endRequest()
	if(!string.indexOf(ctype,"mp3")) return null;
	return bdmp3;  
}


mainForm.show() 
return win.loopMessage();



友情链接:Autohotkey中文帮助Autohotkey官网Autohotkey中文网联系作者免GooglePlay APK下载

 主题设计 • skyfrit.com  Thinkai's Blog | 保留所有权利

44 queries in 1.815 seconds |