Visual Studio 2005 C# 读写Excel文件
做作业的时候查了一点儿资料,
用的vs2k5 读 excel
发现用起来非常简单。。。现在编程语言没话说! 项目-添加引用-COM-Microsoft Excel 12.0 Object Library
&& -Microsoft Office 12.0 Object Library using Microsoft.Office.Core;
using Microsoft.Office.Interop.Excel;
using System.IO;
using System.Reflection; string originalFile = System.Windows.Forms.Application.StartupPath + @".\a.xlsx";
string outputFile;
SaveFileDialog save = new SaveFileDialog();
save.InitialDirectory = "D:\\";
save.Filter = "Excel files (*.xlsx)|*.xlsx|All files (*.*)|*.*";
save.FilterIndex = ;
save.RestoreDirectory = true;
if (save.ShowDialog() == DialogResult.OK)
{
try
{
outputFile = save.FileName;
System.IO.File.Copy(originalFile, outputFile, true);
ExcelRS = new Microsoft.Office.Interop.Excel.ApplicationClass();
//打开目标文件outputFile
RSbook = ExcelRS.Workbooks.Open(outputFile, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing, missing);
//设置第一个工作溥
RSsheet = (Microsoft.Office.Interop.Excel.Worksheet)RSbook.Sheets.get_Item();
//激活当前工作溥
RSsheet.Activate();
RSsheet.Cells[, ] = dataGridView1.SelectedRows.Count;
for (int i = ; i < dataGridView1.SelectedRows.Count; ++i)
{
for (int j = ; j < ; ++j)
{
RSsheet.Cells[i + , j + ] = dataGridView1.Rows[dataGridView1.SelectedRows[i].Index].Cells[j].Value.ToString().Trim();
// RSsheet.Cells
RSsheet.get_Range(RSsheet.Cells[i + , j + ], RSsheet.Cells[i + , j + ]).EntireColumn.ColumnWidth = ;
//RSsheet.get_Range(RSsheet.Cells[i + 2, j + 1], missing).auto
}
}
RSbook.Save();
ExcelRS.DisplayAlerts = true;
ExcelRS.Visible = true;
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
ExcelRS.Quit();
}
} OpenFileDialog open = new OpenFileDialog();
open.InitialDirectory = @"D:\";
open.Filter = "Excel files (*.xlsx)|*.xlsx|All files (*.*)|*.*";
open.FilterIndex = ;
open.RestoreDirectory = true;
if (open.ShowDialog() == DialogResult.OK)
{
try
{
ExcelRS = new Microsoft.Office.Interop.Excel.ApplicationClass();
RSbook = ExcelRS.Workbooks.Open(open.FileName, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing, missing);
RSsheet = (Microsoft.Office.Interop.Excel.Worksheet)RSbook.Sheets.get_Item();
RSsheet.Activate();
Microsoft.Office.Interop.Excel.Range range = RSsheet.get_Range("A" + i, Type.Missing);
counts = int.Parse(range.Text.ToString().Trim());
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
ExcelRS.Quit();
conn.Close();
}
} 评论这张 转发至微博 转发至微博 阅读()| 评论() |
用微信 “扫一扫” 将文章分享到朋友圈。 用易信 “扫一扫” 将文章分享到朋友圈。 喜欢 推荐 0人 | 转载
Visual Studio 2005 C# 读写Excel文件的更多相关文章
- Visual Studio 2005 搭建Windows CE 6.0环境之准备
Microsoft Visual Studio 2005 Visual Studio 2005 Professional 官方90天试用版英文版:http://download.microsoft.c ...
- Visual Studio 2005安装qt-win-commercial-src-4.3.1,并设置环境变量
虽然已经在Visual Studio 2005下安装Qt4已经n次了,还是打算在上写写安装方法. qt-win-commercial-src-4.3.1.zip.qt-vs-integration-1 ...
- Visual Studio 2005 移植 - WINVER,warning C4996, error LINK1104
Visual Studio 2005 移植 - WINVER,warning C4996, error LINK1104 一.WINVER Compile result: WINVER not d ...
- visual studio 2005 win7 64位版下载
http://www.121down.com/soft/softview-19659.html 软件标签: visual studio visual studio 2005是由微软推出的一款基于.ne ...
- Visual Studio 2005 移植 (札记之一)【zhuan】
Visual Studio 2005 移植 - WINVER,warning C4996, error LINK1104 一.WINVER Compile result: WINVER not d ...
- 【DEBUG】 Visual Studio 2005 DEBUG集
一. fatal error C1083: 无法打开包括文件:"stdint.h": No such file or directory stdint.h是c99标准的头文件,vc ...
- vue-electron 使用sqlite3数据库,执行npm run build 报错 .NET Framework 2.0 SDK,Microsoft Visual Studio 2005[C:\temp\wechat\node_modules\sqlite3\build\binding.sln]
问题描述 vue-electron 使用sqlite3数据库,执行npm run build 报错如下: .NET Framework 2.0 SDK,Microsoft Visual Studio ...
- vs里 .sln和.suo 文件 Visual Studio里*.sln和*.suo文件的作用
Visual Studio里*.sln和*.suo文件的作用 VS项目采用两种文件类型(.sln 和 .suo)来存储特定于解决方案的设置.这些文件总称为解决方案文件,为解决方案资源 ...
- Using Nuget in Visual Studio 2005 & 2008
NuGet is a Visual Studio extension that makes it easy to install and update third-party libraries an ...
随机推荐
- 微信小程序入门四: 导航栏样式、tabBar导航栏
实例内容 导航栏样式设置 tabBar导航栏 实例一:导航栏样式设置 小程序的导航栏样式在app.json中定义. 这里设置导航,背景黑色,文字白色,文字内容测试小程序 app.json内容: { & ...
- Agilent RF fundamentals (3)- TX and RX
1Create carrier:谐振器,如433.92Mhz LC谐振 (频偏控制) 2Add data to carrier 加载数据 3Amplify to broadcast :放大器,如NPN ...
- linux, windows, mac, ios等平台GCC预编译宏判断
写跨平台c/c++程序的时候,需要搞清各平台下面的预编译宏,区分各平台代码.而跨平台c/c++编程,GCC基本在各平台都可以使用.整理了一份各平台预编译宏的判断示例. 需要注意几点: * window ...
- SSH使用总结(xml配置)
beans.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...
- 处理get中文乱码
package com.servlet; import java.io.IOException; import java.io.PrintWriter; ...
- LinuxCentos6安装中文输入法
第一步.先安装中文语言包: 执行以下命令 [root@bogon 桌面]# yum install fonts-chinese.noarch [root@bogon 桌面]# yum install ...
- 如何移除双系统mac中的windows系统
双系统 双系统即在电脑的不同分区中安装两个系统,两个系统不会互相影响,但是同时只能有一个系统正在运行,并且必须通过重启的方式来更换系统. 双系统一般由于解决对不同系统的需求,而且在电脑中直接安装系统也 ...
- 洛谷P3585 [POI2015]PIE
传送门 题目大意:有个n*m的格子图,要求'x'点要被染成黑色 有个a*b的印章,'x'是可以染色的印章上的点. 要求用印章去染色格子 (1)印章不可以旋转. (2)不能把墨水印到纸外面. (3)纸上 ...
- [BZOJ]4034: [HAOI2015]树上操作
[HAOI2015]树上操作 传送门 题目大意:三个操作 1:a,b,c b节点权值+c 2:a,b,c 以b为根的子树节点权值全部+c 3:a,b 查询b到根路径的权值和. 题解:树链剖分 操作1 ...
- C#网络编程(订立协议和发送文件) - Part.4
文件传输 前面两篇文章所使用的范例都是传输字符串,有的时候我们可能会想在服务端和客户端之间传递文件.比如,考虑这样一种情况,假如客户端显示了一个菜单,当我们输入S1.S2或S3(S为Send缩写)时, ...