最近要用DSOFRAMER做为一个客户端OFFICE访问工具,而且需要把EXCEL内的文件数据导出,总结了几个简单的方法,以备后用:)
- try {
- var obj;
- obj = new Object(oframe.ActiveDocument);//获得当前控件的文档对象
- if(obj !=null){
- var xls;
- var slt;
- xls = obj.Application;
- var xlsheet = xls.Worksheets(1);
- alert(xls.ActiveCell.value);//当前cell的值
- //xls.Range("A1:D5").Select;//selected the gived rang
- slt = xls.selection;//get the selected area
- var rg = slt.Address(false, false);//get the rang such as a1:b5
- var aryReg = rg.split(":");//split the rangs
- //alert(slt.Address(rowAbsolute=true))
- //alert(xls.ActiveCell.row);
- //alert(xls.ActiveCell.column);
- //xlsheet.Range("A1:A1").value = "KKKK";
- var xr = xlsheet.Range(aryReg[0]);
- var beginRow = xr.row,beginColumn = xr.column;
- alert(beginRow + "," + beginColumn);
- xr = xlsheet.Range(aryReg[1]);
- var endRow = xr.row,endColumn = xr.column;
- alert(endRow + "," + endColumn);
- //alert(xlsheet.UsedRange.value);
- //alert(slt.Rows.Count);
- //alert(slt.Columns.Count);
- //xlsheet.Cells(1,1) = 123;
- //alert(xlsheet.Cells.Count);所有的cells count,is wrong
- //xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,7)).mergecells=true;
- //xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,7)).value="test";
- delete obj;
- }
- } catch(e) {
- alert(e.description);
- }