创建EXCLE 文档的例子
来源:互联网 发布:淘宝的活动有哪些 编辑:程序博客网 时间:2024/06/13 13:17
创建EXCLE 文档的例子
1. 选择 "References", 右键点击,选择"Add Reference..."
2. 选择 ".NET" , 选择 "Microsoft.Office.Interop.Execl ..."
3. 选择 OK
4. 检察 Properties 属性,检察 "Embed Interop Types" 是否为 True, 设置为True.
用下面的例子代码:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;using Excel = Microsoft.Office.Interop.Excel;namespace CreateExcelWorkbook{ class Program { static void Main(string[] args) { int[] values = {4, 6, 18, 2, 1, 76, 0, 3, 11}; CreateWorkbook(values, @"C:\SampleFolder\SampleWorkbook.xls"); } static void CreateWorkbook(int[] values, string filePath) { Excel.Application excelApp = null; Excel.Workbook wkbk; Excel.Worksheet sheet; try { // Start Excel and create a workbook and worksheet. excelApp = new Excel.Application(); wkbk = excelApp.Workbooks.Add(); sheet = wkbk.Sheets.Add() as Excel.Worksheet; sheet.Name = "Sample Worksheet"; // Write a column of values. // In the For loop, both the row index and array index start at 1. // Therefore the value of 4 at array index 0 is not included. for (int i = 1; i < values.Length; i++) { sheet.Cells[i, 1] = values[i]; } // Suppress any alerts and save the file. Create the directory // if it does not exist. Overwrite the file if it exists. excelApp.DisplayAlerts = false; string folderPath = Path.GetDirectoryName(filePath); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } wkbk.SaveAs(filePath); } catch { } finally { sheet = null; wkbk = null; // Close Excel. excelApp.Quit(); excelApp = null; } } }}
- 创建EXCLE 文档的例子
- POI 创建一个日历的excle
- vbscript 读取excle文档
- Java io导出html制作的excle报表例子
- java实现txt、excle、pdf、doc文档的在线预览
- 非常简单的java通过poi创建excle表格
- poi 操作excle小例子
- .NET中实现Word,Excle文档到PDF文档的转化
- C#创建xml文档小例子
- 在linux中创建和解压文档的11个 tar 命令例子
- Java四种读取和创建XML文档的例子教程
- 学习总结篇 java创建excle 解析excle (poi)
- 如何在程序中实现PPT,Excle等文档的预览功能~~?
- 创建进程的例子
- 创建数据库的例子
- 多线程的创建例子
- Excle的使用
- excle的导入程序
- Android模拟按键——源码环境下开发应用程序
- 【Android 开发教程】显示普通对话框
- s19文件解析
- 【Android 开发教程】显示进度对话框
- 程序员201102摘要
- 创建EXCLE 文档的例子
- 【Android 开发教程】显示复杂对话框
- android-如何在系统settings里添加设置选项
- [UvaOJ - Getting Started] 10071 - Back to High School Physics
- gdb+gdb Server安装配置zz
- Android测试汇总
- 【Android 开发教程】链接Activities
- 【java】用getBytes()方法的要注意啰
- jsp 页面自动刷新