加载excel.doc

上传人:hw****26 文档编号:3035266 上传时间:2019-05-18 格式:DOC 页数:6 大小:41KB
下载 相关 举报
加载excel.doc_第1页
第1页 / 共6页
加载excel.doc_第2页
第2页 / 共6页
加载excel.doc_第3页
第3页 / 共6页
加载excel.doc_第4页
第4页 / 共6页
加载excel.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

1、using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using Excel=Microsoft.Office.Interop.Excel;using System.Reflection;namespace WindowsApplication5public partial class Form1 : Formpublic Form1(

2、)InitializeComponent();Excel.Application app = new Excel.Application(); private void Form1_Load(object sender, EventArgs e)string strFileName = “d:a.xls“;Object refmissing = System.Reflection.Missing.Value;this.webBrowser1.Navigate(strFileName,false);object axWebBrowser = this.webBrowser1.ActiveXIns

3、tance;private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)Object refmissing = System.Reflection.Missing.Value;object axWebBrowser =this.webBrowser1.ActiveXInstance;object oApplication = axWebBrowser.GetType().InvokeMember(“Document“,BindingFlags.GetProper

4、ty,null, axWebBrowser,null);Excel.Workbook wbb = (Excel.Workbook) oApplication;Excel.ApplicationClass excel = wbb.Application as Excel.ApplicationClass;Excel.Workbook wb = excel.Workbooks1;Excel.Worksheet ws = wb.Worksheets1as Excel.Worksheet;ws.Cells.Font.Name =“Verdana“;ws.Cells.Font.Size = 14;ws.

5、Cells.Font.Bold =true;Excel.Range range = ws.Cells;Excel.Range oCell = range10, 10 as Excel.Range;oCell.Value2 =“你好“;wb.Save();private void button1_Click(object sender, EventArgs e) Object refmissing = System.Reflection.Missing.Value;foreach (Excel.Workbook temp in app.Workbooks)MessageBox.Show(temp

6、.Name.ToString();temp.Save();temp.Saved = true;temp.Close(false, refmissing, refmissing);/没效果app.Workbooks.Close();/出错,异常来自 HRESULT:0x800A03ECExcel.Application excelApp = new Excel.Application();protected void Form1_Load(object sender, EventArgs e)webBrowser1.Navigate(“d:a.xls“, false);protected voi

7、d webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)object axWebBrowser = this.webBrowser1.ActiveXInstance;Excel.Workbook workbook = (Excel.Workbook) axWebBrowser.GetType().InvokeMember(“Document“,BindingFlags.GetProperty, null,axWebBrowser, null);Excel.Workbook sec

8、ondWorkbook = (Excel.ApplicationClass)workbook.Application).Workbooks1;Excel.Worksheet secondWorksheet = (Excel.Worksheet)secondWorkbook.Worksheets1;secondWorksheet.Cells.Font.Name = “Verdana“;secondWorksheet.Cells.Font.Size = 14;secondWorksheet.Cells.Font.Bold = true;(Excel.Range)secondWorksheet.Ce

9、lls10, 10).Value2 = “你好“;secondWorkbook.Save();protected void button1_Click(object sender, EventArgs e)Missing refmissing = System.Reflection.Missing.Value;foreach (Excel.Workbook temp in excelApp.Workbooks)MessageBox.Show(temp.Name.ToString();temp.Save();temp.Saved = true;temp.Close(false, refmissing, refmissing);excelApp.Workbooks.Close();/没报错

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育教学资料库 > 精品笔记

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。