




已阅读5页,还剩14页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
foxtable常用代码汇总1col打开列窗口with tables(员工) .cols(照片).openwindow() .cols(备注).closewindow()end with按钮或菜单2col关闭列窗口with tables(员工) .cols(照片).openwindow() .cols(备注).closewindow()end with按钮或菜单3col移动列到指定位置with tables(订单) .cols(日期).move(0) .cols(客户).move(1) .cols(产品).move(2)end with按钮或菜单将日期、客户、产品移到前三列的位置4col冻结列currenttable.cols.frozen = 2按钮或菜单冻结前两列5col取消冻结列currenttable.cols.frozen = 0按钮或菜单6col从table中移除指定的列if tables(订单).cols.contains(折扣) then tables(订单).cols.remove(折扣)end if按钮或菜单在订单表中移除折扣列7col一次移除多列tables(订单).cols.remove(折扣,金额)按钮或菜单8datacol锁定某表某列datatables(订单).datacols(折扣).allowedit = false 按钮或菜单9datacol取消锁定某表某列datatables(订单).datacols(折扣).allowedit = true按钮或菜单10datacol动态地修改表达式列的计算公式datatables(订单).datacols(金额).expression = 数量 * 单价datatables(订单).datacols(金额).expression = 数量 * 单价 * (1 - 折扣)按钮或菜单expression属性只对表达式列有效11datacol返回列的名称for each dc as datacol in datatables(订单).datacols output.show(dc.name)next按钮或菜单列出订单表中所有列的名称12datacol增加临时列,并可给临时列设置表达式datatables(订单).datacols.add(金额, gettype(double), 数量 * 单价 * (1 - 折扣)按钮或菜单通过代码增加的临时列,在重新打开项目文件后,将不复存在13datacol删除临时列if datatables(订单).datacols.contains(金额) then datatables(订单).datacols.delete(金额)end if按钮或菜单通过add方法增加的临时列,可以用delete方法删除14datacol一列设公式,另列得结果if e.datacol.name = 第一列 then if e.datarow.isnull(第一列) then e.datarow(第二列) = nothing else e.datarow(第二列) = eval(e.datarow(第一列),e.datarow) end ifend ifdatacolchanged事件假定希望根据第一列输入的计算公式,在第二列得出计算结果15datarow删除行datatables(订单).datarows(0).delete() 按钮或菜单删除订单表中的第一行delete会返回逻辑值,如果删除成功,则返回true,否则返回false16datarow重新加载行datatables(订单).datarows(1).load()按钮或菜单重新加载订单表的第二行17datarow撤销修改datatables(订单).datarows(1).load(false)按钮或菜单撤销对订单表第二行的修改18datarowdatatable中增加一行with datatables(订单).datarows .addnew() 增加一行 end with按钮或菜单19datarow删除指定位置的行with datatables(订单).datarows .delete(0) 删除第一行 end with按钮或菜单20datarow清除所有行with datatables(单).datarows .delete(0) 删除第一行 end with按钮或菜单21datarow按日期列求月份dim dr as datarow =e.datarowif e.datacol.name =开始时间 then if dr.isnull(开始时间) = false then dr(月) = dr(开始时间).month else dr(月) = nothing end ifend if表datacolchanged事件22datarow新增行编号自动加e.datarow(编号) = e.datatable.compute(max(编号) + 1datarowadding事件假定表中有一个编号列,希望新增行的时候,编号列能够自动加这个例子其实没有什么意义的,对于外部表使用自动增量主键列,对于内部表使用表达式列引用内部编号列“_identidy”,是更好的选择。23datatable获得指定名称的datatabledim dt as datatabledt = datatables(订单)按钮或菜单24datatable锁定表datatables(订单).allowedit = false按钮或菜单allowedit属性25datatable取消锁定表datatables(订单).allowedit = true按钮或菜单allowedit属性26datatable按回车键向下移动光标datatables(订单).enterkeyactiondown = true按钮或菜单enterkeyactiondown属性27datatable在datatable中增加一行,dim dr as datarow按钮或菜单其实我们很少直接向datatab28datatable保存数据datatables(订单).save()按钮或菜单单保存数据29datatable同时保存数据和设置datatables(订单).save(true)按钮或菜单保存设置比较耗时,会影响保存速度。菜单中的保存命令是同时保存数据和设置的。30datatable自制保存按钮for each dt as datatable in datatables按钮或菜单这个按钮就能保存所有表,但是不会保存设置;对于一个成熟的、已经交付使用的项目,有时是没有必要保存设置的。31datatable删除符合条件的行datatables(订单).deletefor(日期 0 andalso drs(n)(总分) = drs(n-1)(总分) then 如果总分和上一行相同 drs(n)(总分排名) = drs(n-1)(总分排名) 则排名等于上一行 else drs(n)(总分排名) = n + 1 设置排名 end if next next按钮或菜单例子,可以参考casestudy目录下的文件:成绩排名.table36datatable找出符合条件的行,并将指定列的内容替换为指定值datatables(订单).replacefor(折扣, 0.15, 数量 600)按钮或菜单将订单表中,订购数量大于600的订单的折扣设为0.1537datatable选定某一区域currenttable.select(1,2,7,6)按钮或菜单选定当前表第二行第三列至第八行第7列之间的区域38datatable选定指定位置的单元格currenttable.select(0,0)按钮或菜单选定当前表的第1行第1列39datatable选定整个某列currenttable.select(0, 1, currenttable.rows.count - 1, 1)按钮或菜单选定整个第二列40datatable保存并重新加载所有表for each dt as datatable in datatables dt.loadnext按钮或菜单在多人同时编辑数据的时候,通过执行此方法,可以得到最新的数据41datatable设置加载条件重新加载with datatables(订单) .loadfilter = 产品 = pd01 .load()end with按钮或菜单加载产品为pd01的订单42datatable撤销对表a的修改datatables(表a).rejectchanges()按钮或菜单撤销自打开文件或最近一次保存以来,对该表做出的修改43datatable移除符合条件的行datatables(订单).removefor(产品 = pd01)按钮或菜单44datatable根据条件统计表中数据dim total as integerdim amount as doublewith datatables(订单) total = .compute(sum(数量) amount = .compute(sum(金额)end with按钮或菜单计算总的销售数量和金额45datatable根据条件统计表中数据dim total as longtotal = datatables(订单).compute(sum(数量), 产品 = pd01)按钮或菜单计算产品pd01的销售数量46datatable根据条件统计表中数据dim customers as list(of string)dim total as integercustomers = datatables(订单).getuniquevalues(, 客户)for each customer as string in customers total = datatables(订单).compute(sum(数量), 客户 = & customer & ) output.show(customer & : & total)next按钮或菜单计算每个客户的订购数量47datatable删除表datatables.delete(统计表1)按钮或菜单删除通过代码增加的临时表。48datatables按条件填充并求和dim d as date = date.todaydim m as integer = d.monthdim f as new filler f.sourcetable = datatables(人员表) 指定数据来源 f.sourcecols = 姓名,性别 指定数据来源列 f.datatable = datatables(发放记录) 指定数据接收表 f.datacols = 姓名,性别 指定数据接收列 f.fill() 填充数据 for each dr as datarow in datatables(发放记录).datarows dr(工资) = datatables(人员表).compute(sum(工资), 姓名= & dr(姓名) & and 月= & m & ) if dr.isnull(发放日期) = true then dr(发放日期) = d end if next按钮或菜单49datatables按条件重新加载数据datatables(订单).loadfilter = 日期 = # & date.today & #datatables(订单).load()50delete语句删除指定条件的行delete from 订单 where year(日期) = 1998按钮或菜单表示删除1998年的订单51excel报表table保存为excel文件中的一个工作表currenttable.saveexcel(c:datatest.xls,订单,false)按钮或菜单saveexcel(filename, sheetname, selectedrowsonly)filename: 目标excel文件名,含路径。sheetname: 工作表名。selectedrowsonly:逻辑型,设为true,只保存选定行,否则包括所有行。52excel报表打印模板dim book as new xls.book(projectpath & attachments出库单.xls)book.build() 生成细节区book.save(c:reportstest.xls) 保存工作簿dim proc as new process 打开工作簿proc.file = c:reportstest.xlsproc.start()按钮或菜单如果book来自于一个模板文件,必须先调用方法,才能生成细节区。53excel报表将datalist的内容保存为excel文件中的一个工作表。dim dst as winform.datalist = e.form.controls(datalist1)dst.saveexcel(c:datatest.xls,订单,false)按钮或菜单saveexcel(filename, sheetname, selectedrowsonly)filename: 目标excel文件名,含路径。sheetname: 工作表名。selectedrowsonly:逻辑型,设为true,只保存选定行,否则包括所有行。54excel报表报表中插入一行dim book as new xls.book(c:reportstest.xls) 定义一个excel工作簿dim sheet as xls.sheet = book.sheets(0) 引用工作簿的第一个工作表sheet.rows.insert(0) 在最前面插入一行book.save(c:reportstest.xls)dim proc as new process proc.file = c:reportstest.xlsproc.start()按钮或菜单55excel报表报表中插入一列dim book as new xls.book(c:reportstest.xls) 定义一个excel工作簿dim sheet as xls.sheet = book.sheets(0) 引用工作簿的第一个工作表sheet.cols.insert(0) 在最前面插入一列book.save(c:reportstest.xls)dim proc as new process proc.file =c:reportstest.xlsproc.start()按钮或菜单56excel报表代码生成报表(导出报表)dim dt as table = tables(订单)dim book as new xls.book 定义一个excel工作簿dim sheet as xls.sheet = book.sheets(0) 引用工作簿的第一个工作表dim style as xls.style = book.newstyle 新建一个样式style.backcolor = color.red 样式的背景颜色设为红色for c as integer = 0 to dt.cols.count -1 添加列标题 sheet(0, c).value = dt.cols(c).namenextfor r as integer = 0 to dt.rows.count - 1 填入数据 for c as integer = 0 to dt.cols.count -1 sheet(r +1, c).value = dt.rows(r)(c) next if dt.rows(r)(折扣) = 0.15 then 如果折扣大于等于0.15 sheet(r + 1,dt.cols(折扣).index).style = style 设置折扣单元格的样式 end ifnextdim st2 as xls.style = book.newstylest2.format = yyyy-mm-ddsheet.cols(dt.cols(日期).index).style = st2打开工作簿book.save(c:reportstest.xls)dim proc as new process proc.file = c:reportstest.xlsproc.start()按钮或菜单带样式导出57excel报表设置行高、样式及强制换页dim book as new xls.book(c:reportstest.xls) 定义一个excel工作簿dim sheet as xls.sheet = book.sheets(0) 引用工作簿的第一个工作表dim style as xls.style = book.newstyle() 定义新样式style.forecolor = color.red 设置样式的字体颜色sheet.rows(0).height = 40 设置第1行的行高sheet.rows(0).style = style 设置第1行的样式sheet.rows(20).pagebreak = true 在第21行处强制换页book.save(c:reportstest.xls)dim proc as new process proc.file =c:reportstest.xlsproc.start()按钮或菜单58excel报表设置列宽、样式及分页dim book as new xls.book(c:reportstest.xls) 定义一个excel工作簿dim sheet as xls.sheet = book.sheets(0) 引用工作簿的第一个工作表dim style as xls.style = book.newstyle() 定义新样式style.forecolor = color.red 设置样式的字体颜色sheet.cols(0).width = 120 设置第1列的宽度sheet.cols(0).style = style 设置第1列的样式sheet.cols(4).pagebreak = true 在第5列处强制分页book.save(c:reportstest.xls)dim proc as new process proc.file = c:reportstest.xlsproc.start()按钮或菜单59excel报表单元格样式、超链接dim book as new xls.book() 定义一个excel工作簿dim sheet as xls.sheet = book.sheets(0) 引用工作簿的第一个工作表dim style as xls.style = book.newstyle() 定义新样式style.forecolor = color.red 设置样式的字体颜色sheet(0,0).style = stylesheet(0,0).value = 邮件sheet(0,0).hyperlink = mailto:book.save(c:reportstest.xls)dim proc as new process proc.file = c:reportstest.xlsproc.start()按钮或菜单60excel报表缩放打印dim book as new xls.book 定义一个excel工作簿dim sheet as xls.sheet = book.sheets(0) 引用工作簿的第一个工作表with sheet.printsetting .autoscale = true 自动缩放 .fitpagesdown = 1 垂直方向缩为1页 end withfor i as integer = 0 to 50 向工作表的单元格中设置值 sheet(i, 0).value = (i + 1) * 10 sheet(i, 1).value = (i + 1) * 100 sheet(i, 2).value = (i + 1) * 1000nextbook.save(c:reportstest.xls) 保存工作簿dim proc as new process 打开工作簿proc.file = c:reportstest.xlsproc.start()按钮或菜单61excel报表页面设置dim book as new xls.book dim sheet as xls.sheet = book.sheets(0)with sheet.printsetting .paperkind = 9 设为a4纸 .landscape = true 横向打印 .marginleft = 20 左右边距设为20毫米 .marginright = 20 .margintop = 15 上下边距设为15毫米 .marginbottom = 15end with按钮或菜单62excel报表页眉页脚dim book as new xls.book 定义一个excel工作簿dim sheet as xls.sheet = book.sheets(0) 引用工作簿的第一个工作表with sheet.printsetting 页眉左边为日期,中间为时间,右边为表名 .header = &l&d &c&t &r&a 在页脚右边打印页号和总页数 .footer = &r第&p页,总&n页end withfor i as integer = 0 to 100 向工作表的单元格中设置值 sheet(i, 0).value = (i + 1) * 10 sheet(i, 1).value = (i + 1) * 100 sheet(i, 2).value = (i + 1) * 1000nextbook.save(c:reportstest.xls) 保存工作簿dim proc as new process 打开工作簿proc.file = c:reportstest.xlsproc.start()按钮或菜单63excel报表打印模式、页面居中、网络线、标题等dim book as new xls.book 定义一个excel工作簿dim sheet as xls.sheet = book.sheets(0) 引用工作簿的第一个工作表with sheet.printsetting .blackandwhite = true 用黑白模式打印,即使你安装的是彩色打印 .centerhorizontal = true 表格水平方向页面居中 .centervertical = true 表格垂直方向页面居中 .printgridlines = true 打印网格线 .printheaders = true 打印列标题end withfor i as integer = 0 to 100 向工作表的单元格中设置值 sheet(i, 0).value = (i + 1) * 10 sheet(i, 1).value = (i + 1) * 100 sheet(i, 2).value = (i + 1) * 1000nextbook.save(c:reportstest.xls) 保存工作簿dim proc as new process 打开工作簿proc.file = c:reportstest.xlsproc.start()按钮或菜单64excel报表单元格对齐数据dim book as new xls.book() 定义一个excel工作簿dim sheet as xls.sheet = book.sheets(0) 引用工作簿的第一个工作表dim style as xls.style = book.newstyle() 定义新样式style.forecolor = color.red 设置样式的字体颜色style.alignhorz = xls.alignhorzenum.centerstyle.alignvert = xls.alignvertenum.centersheet.rows(0).height = 50 sheet.cols(0).width = 120sheet(0,0).value = 邮件sheet(0,0).style = stylebook.save(c:reportstest.xls)dim proc as new process proc.file = c:reportstest.xlsproc.start()按钮或菜单下面两个属性用于对齐数据。alignhorz设置水平对齐方式,xls.alignhorzenum型枚举,主要可选值有:center: 居中general:默认left: 靠左right: 靠右alignvert设置垂直对齐方式,xls.alignvertenum,主要可选值有:bottom: 靠底center: 居中top: 靠上undefined:默认65excel报表单元格背景颜色和字体颜色dim dt as table = tables(订单)dim book as new xls.book 定义一个excel工作簿dim sheet as xls.sheet = book.sheets(0) 引用工作簿的第一个工作表dim style as xls.style = book.newstyle 新建一个样式style.backcolor = color.red 样式的背景颜色设为红色dim style1 as xls.style = book.newstyle 新建一个样式style1.forecolor = color.blue 样式的字体颜色设为蓝色按钮或菜单66excel报表单元格边框设置dim book as new xls.book() 定义一个excel工作簿dim sheet as xls.sheet = book.sheets(0) 引用工作簿的第一个工作表dim style as xls.style = book.newstyle() 定义新样式style.bordertop = xls.linestyleenum.thinstyle.borderbottom = xls.linestyleenum.thinstyle.borderleft = xls.linestyleenum.thinstyle.borderright = xls.linestyleenum.thinstyle.bordercolortop = color.redstyle.bordercolorbottom = color.redstyle.bordercolorleft = color.redstyle.bordercolorright = color.redfor r as integer = 1 to 5 for c as integer =1 to 5 sheet(r,c).style = style nextnextbook.save(c:reportstest.xls) dim proc as new process proc.file = c:reportstest.xlsproc.start()按钮或菜单属性 说明 备注 bordertop 返回或设置上边框的类型。 xls.linestyleenum型枚举,主要可选值有:dashed: 虚线dotted:点线double:双实线hair:头发丝一样的细线(一个像素)medium:中等实线mediumdashdotdotted:中等的(短线+点+点)mediumdashdotted: 中等的(短线+点)mediumdashed: 中等虚线none:无thick:粗线thin:细线thindashdotdotted:细(短线+点+点)thindashdotted:细(短线+点) borderbottom 返回或设置下边框的类型。 borderleft 返回或设置左边框类型。 borderright 返回或设置右边框类型。 bordercolortop 返回或设置上边框颜色 bordercolorbottom 返回或设置下边框颜色 bordercolorleft 返回或设置左边框颜色 bordercolorright 返回或设置上边框颜色 67excel报表单元格斜线设置dim book as new xls.book()dim sheet as xls.sheet = book.sheets(0)dim style as xls.style = book.newstyle()style.diagonalstyle= xls.linestyleenum.thinstyle.diagonalcolor =color.redstyle.diagonal = xls.diagonalenum.backwardfor r as integer = 1 to 2 for c as integer =1 to 2 sheet(r,c).style = style nextnextbook.save(c:reportstest.xls) dim proc as new process proc.file = c:reportstest.xlsproc.start()按钮或菜单和斜线设置有关的属性:diagonal返回或设置斜线的方向,xls.diagonalenum型枚举,可选值有:backward:反斜线forward:斜线none:无 diagonalcolor 返回或设置斜线颜色 diagonalstyle返回或设置斜线的类型,xls.linestyleenum型枚举,主要可选值有:dashed: 虚线dotted:点线double:双实线hair:头发丝一样的细线(一个像素)medium:中等实线mediumdashdotdotted:中等的(短线+点+点)mediumdashdotted: 中等的(短线+点)mediumdashed: 中等虚线none:无thick:粗线thin:细线thindashdotdotted:细(短线+点+点)thindashdotted:细(短线+点) 68excel报表单元格内容自动换行dim dt as table = tables(订单)dim book as new xls.book 定义一个excel工作簿dim sheet as xls.sheet = book.sheets(0) 引用工作簿的第一个工作表dim style as xls.style = book.newstyle 新建一个样式style.wordwrap = true 单元格内容自动换行按钮或菜单69excel报表在excel报表模板中插入一个标记dim book as new xls.book(c:book5.xls)book.marks.add(用户名,user.name)book.build()book.save(c:reportstest.xls) dim proc as new processproc.file = c:reportstest.xlsproc.start()按钮或菜单利用marks集合,我们可以在报表模板中插入标记,然后在生成报表的时候,将标记替换为真正的值。在excel报表模板中插入一个标记的格式为:示例假定报表中某个位置需要打印出当前登录用户的名称,我们可以在设计报表的时候,在该处插入标记:标记的名称可以根据需要取。然后在生成报表之前,利用marks集合,将标记替换为真正的用户:70excel报表插入图片dim book as new xls.book 定义一个excel工作簿dim sheet as xls.sheet = book.sheets(0) 引用工作簿的第一个工作表for i as integer = 0 to 9 向工作表的单元格中设置值 sheet(i, 0).value = (i + 1) * 10 sheet(i, 1).value = (i + 1) * 100 sheet(i, 2).value = (i + 1) * 1000nextsheet(10,2).value = new xls.picture(getimage(c:foxtable.ico)book.save(c:reportstest.xls) 保存工作簿dim proc as new process 打开工作簿proc.file = c:reportstest.xlsproc.start()按钮或菜单单元格的value属性,不仅可以设置为数据,还可以设置为一个xls.picture对象。xls.picture用于定义一个可插入到excel单元格的图片,语法为:new xls.picture(image)或new xls.picture(image, left, top, width, height)参数:image: 要插入的图片。left: 左边距,单位为像素。top: 上边距,单位为像素。width: 宽度,单位为像素。height: 高度,单位为像素。可用getimage函数从指定的图标文件中获得图标,如果文件已经事先复制到管理项目的images子目录下,则只需指定文件名即可,否则需要包括路径。71excel报表在excel报表模板中加上制单人信息dim book as new xls.book(projectpath & attachments出库单.xls) 打开模板dim sheet as xls.sheet = book.sheets(0)sheet(6,6).value = 制单人: & user.name 修改模板,加入制单人信息book.build() 生成细节区book.save(c:reportstest.xls) 保存工作簿dim proc as new process 打开工作簿proc.file = c:reportstest.xlsproc.start()按钮或菜单72row当前选定的行dim dr as row = tables(订单).current按钮或菜单73row删除选定行tables(订单).current.delete()
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 海南省省直辖县级行政单位2025年-2026年小学六年级数学课后作业(下学期)试卷及答案
- 2025标准版委托贷款合同模板
- 2025年中石化加油站招聘面试官青睐的应聘技巧与答案解析
- 2025年公墓管理员面试常见问题及答案示例
- 3.《鸿门宴》(教学设计)高一语文同步高效课堂(统编版 必修下册)
- 2025年医疗美容咨询师招聘面试指南与模拟题解析
- 2025吊装设备购销合同范本
- 2025年中国钢研科技集团招聘笔试题型分析与应对策略
- 2025年健身教练专业笔试技巧与模拟题解答
- 2025年导游职业技能鉴定面试预测题与应对策略
- 教育机构兼职教师聘用合同
- 湖北省高中名校联盟2026届高三上学期第一次联合测评物理试题(含答案)
- 形势与政策正确认识中国经济热点问题讲稿-2025秋版本
- 2025年广东省中考化学真题及答案
- 托盘运输知识培训内容课件
- 2025年小学信奥选拔试题及答案
- 第2课+西方国家古代和近代政治制度的演变2025-2026学年高二上学期历史统编版(2019)选择性必修1
- 民法典出租房屋合同条款
- 酒店安全巡查日常检查记录表
- 网络信息安全防护策略及措施
- 卒中救治中心建设汇报
评论
0/150
提交评论