前台定义:
<body>
    <form id="form1" runat="server">
    <div>
     
  <object id="sheet" classid="clsid:0002E559-0000-0000-C000-000000000046" name="sheet">   
  </object>       
   </div>
    </form>
</body>后台: protected void Page_Load(object sender, EventArgs e)
    {       
        if (!IsPostBack)
        {
            Microsoft.Office.Interop.Owc11.SpreadsheetClass sheet = new Microsoft.Office.Interop.Owc11.SpreadsheetClass();           
            sheet.ActiveCell[1,1] = "1";          
        }
}为什么运行后页面上的excel单元格里没有得到在后台赋的值?另求关于owc的资料,谢谢

解决方案 »

  1.   

    可能是由于owc安全的问题.
    IE里把相关的权限都放开吧,这东西现在浏览器很限制的.
      

  2.   

     private void ObjectOwc()
        {
            
            //创建ChartSpace对象来放置图表
            Microsoft.Office.Interop.Owc11.ChartSpace objCSpace = new Microsoft.Office.Interop.Owc11.ChartSpaceClass();        //在ChartSpace对象中添加图表,Add方法返回chart对象
            Microsoft.Office.Interop.Owc11.ChChart objChart = objCSpace.Charts.Add(0);        //指定图表的类型。类型由OWC.ChartChartTypeEnum枚举值得到
            objChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered;        //指定图表是否需要图例
            objChart.HasLegend = true;        //给定标题
            objChart.HasTitle = true;
            objChart.Title.Caption = "分析图";        //给定x,y轴的图示说明
            objChart.Axes[0].HasTitle = true;
            objChart.Axes[0].Title.Caption = " X: 單位名稱";
            objChart.Axes[1].HasTitle = true;        objChart.Axes[1].Title.Caption = " Y: 金額";        //取得部門和金額
            string arryStrDeprt=string.Empty;
            string arryStrMoney = string.Empty;
            for (int a = 0; a < _JcOrderVig.Rows.Count; a++)
            {
                arryStrDeprt = arryStrDeprt + ";" + _JcOrderVig.Rows[a].Cells[0].Text.ToString();
                arryStrMoney = arryStrMoney + ";" + _JcOrderVig.Rows[a].Cells[2].Text.ToString();
            }
            string[] arryDeprt = arryStrDeprt.Split(';');
            string[] arryMoney = arryStrMoney.Split(';');
            string strCategory ="";
            string strValue = "";
            for (int i = 1; i < arryDeprt.Length; i++)
            {
                strCategory =strCategory+ arryDeprt[i] + '\t';
                strValue =strValue+ arryMoney[i] + '\t';
            }
            string strSeriesName = "图例";        
            //添加一个series
            objChart.SeriesCollection.Add(0);        //给定series的名字
            objChart.SeriesCollection[0].SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames,
                +(int)Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName);        //给定分类
            objChart.SeriesCollection[0].SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories,
                +(int)Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, strCategory);        //给定值
            objChart.SeriesCollection[0].SetData
                (Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues,
                (int)Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, strValue);
            //输出成GIF文件.
            string strAbsolutePath = (Server.MapPath(".")) + "\\test.gif";
            objCSpace.ExportPicture(strAbsolutePath, "GIF", 600, 500);        //创建GIF文件的相对路径.
            string strRelativePath = "./test.gif";        //把图片添加到placeholder.
            string strImageTag = "<IMG SRC='" + strRelativePath + "'/>";
            ChartHolder.Controls.Add(new LiteralControl(strImageTag));
        }