OWC 显示和读取Excel数据
在网页中嵌入Excel:
<object id=Spreadsheet1 style="height:100%; width: 100%; border: 1px solid #999; " align="top" classid="clsid:0002E551-0000-0000-C000-000000000046"> <param name="DataType" value="XMLURL"/> <param name="XMLURL" value="templates/test.xml"/> <param name="AllowPropertyToolbox" value="1"/> <param name="AutoFit" value="0"/> <param name="Calculation" value="-4105"/> <param name="Caption" value="Microsoft Office 电子表格"/> <param name="DisplayColumnHeadings" value="-1"/> <param name="DisplayGridlines" value="-1"/> <param name="DisplayHorizontalScrollBar" value="-1"/> <param name="DisplayOfficeLogo" value="-1"/> <param name="DisplayPropertyToolbox" value="0"/> <param name="DisplayRowHeadings" value="-1"/> <param name="DisplayTitleBar" value="0"/> <param name="DisplayToolbar" value="-1"/> <param name="DisplayVerticalScrollBar" value="-1"/> <param name="DisplayWorkbookTabs" value="1"/> <param name="EnableEvents" value="-1"/> <param name="MaxHeight" value="100%"/> <param name="MaxWidth" value="100%"/> <param name="MoveAfterReturn" value="-1"/> <param name="MoveAfterReturnDirection" value="-4121"/> <param name="RightToLeft" value="0"/> <param name="ScreenUpdating" value="-1"/> <param name="EnableUndo" value="-1"/></object>
?
Spreadsheet1.DisplayGridlines = false; 可以控制是否显示网格。
读取Excel内容:
var excelData = new Array();var tempv;var i,j;var sht = Spreadsheet1.ActiveSheet;for(i=1;i<=100;i++) {for(j=1;j<=150;j++) {try {tempv=sht.Cells(i,j).Valueif(tempv != undefined ) {tempv=tempv.toString();if($.trim(tempv)!='' && $.trim(tempv)!='0') {var c = new Object();c.col = i.toString();c.row = j.toString();c.value = tempv;excelData.push(c);}}} catch(ex){ }}}