C# 创建Excel并写入内容
1 增加应用 Microsoft.Office.Interop.Excel
2 引用命名空间 using Excel = Microsoft.Office.Interop.Excel;
/// <summary>
/// If the supplied excel File does not exist then Create it
/// </summary>
/// <param name="FileName"></param>
private void CreateExcelFile(string FileName)
{
//create
object Nothing = System.Reflection.Missing.Value;
var app = new Excel.Application();
app.Visible = false;
Excel.Workbook workBook = app.Workbooks.Add(Nothing);
Excel.Worksheet worksheet = (Excel.Worksheet)workBook.Sheets[1];
worksheet.Name = "Work";
//headline
worksheet.Cells[1, 1] = "FileName";
worksheet.Cells[1, 2] = "FindString";
worksheet.Cells[1, 3] = "ReplaceString"; worksheet.SaveAs(FileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing);
workBook.Close(false, Type.Missing, Type.Missing);
app.Quit();
} /// <summary>
/// open an excel file,then write the content to file
/// </summary>
/// <param name="FileName">file name</param>
/// <param name="findString">first cloumn</param>
/// <param name="replaceString">second cloumn</param>
private void WriteToExcel(string excelName,string filename,string findString,string replaceString)
{
//open
object Nothing = System.Reflection.Missing.Value;
var app = new Excel.Application();
app.Visible = false;
Excel.Workbook mybook = app.Workbooks.Open(excelName, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing);
Excel.Worksheet mysheet = (Excel.Worksheet)mybook.Worksheets[1];
mysheet.Activate();
//get activate sheet max row count
int maxrow = mysheet.UsedRange.Rows.Count + 1;
mysheet.Cells[maxrow, 1] = filename;
mysheet.Cells[maxrow, 2] = findString;
mysheet.Cells[maxrow, 3] = replaceString;
mybook.Save();
mybook.Close(false, Type.Missing, Type.Missing);
mybook = null;
//quit excel app
app.Quit();
}
C# 创建Excel并写入内容的更多相关文章
- 【HDFS API编程】查看HDFS文件内容、创建文件并写入内容、更改文件名
首先,重点重复重复再重复: /** * 使用Java API操作HDFS文件系统 * 关键点: * 1)创建 Configuration * 2)获取 FileSystem * 3)...剩下的就是 ...
- HDFS上创建文件、写入内容
1.创建文件 hdfs dfs -touchz /aaa/aa.txt 2.写入内容 echo "<Text to append>" | hdfs dfs -appen ...
- c# 创建excel表头及内容
主要通过ajax调用函数Getinfo 1.定义表dh DataTable dh = new DataTable(); 2.创建表头 public void CreateCol(string Colu ...
- NPOI 创建Excel,数据读取与写入
<1> using System; using System.Collections.Generic; using System.Linq; using System.Web; using ...
- 使用Java创建Excel,并添加内容
使用Java创建Excel,并添加内容 一.依赖的Jar包 jxl.jar,使用jxl操作Excel Jxl是一个开源的Java Excel API项目,通过Jxl,Java可以很方便的操作微软的Ex ...
- (最全最灵活地)利用Jxl工具包实现Excel表的内容读取 、写入(可向已有表中追加数据)
1.引子 (1)读取 Jxl工具比较强大,可以方便地实现Excel表的读取和写入.另一款工具Poi也具有相似的功能,并且功能更多,运用也相对复杂.Poi读取Excel表内容时,需要先判断其内容格式,如 ...
- 关于java中创建文件,并且写入内容
以下内容完全为本人原创,如若转载,请注明出自:http://www.cnblogs.com/XiOrang/ 前两天在项目中因为要通过http请求获取一个比较大的json数据(300KB左右)并且保存 ...
- Java 创建Excel并逐行写入数据
package com.xxx.common.excel; import java.io.File; import java.io.FileInputStream; import java.io.Fi ...
- 如何使用Java创建Excel(.xls 和 .xlsx)文件 并写入数据
1,需要依赖的jar包, <!-- POI(operate excel) start --> <!-- the version of the following POI packag ...
随机推荐
- Flask 中的 SQLAlchemy 使用教程
Flask 是一个 python web micro framework.所谓微框架,主要是 flask 简洁与轻巧,自定义程度高.相比 django 更加轻量级. 之前一直折腾 django,得益于 ...
- const和violate
const修饰变量 C语言中,const修饰的变量是只读的,本质还是变量,修饰的变量也会在内存中占用空间(这不废话么)本质上const只对编译器有用,在运行时无用.const和类型顺序无要求,一般类型 ...
- Jquery UI的datepicker插件使用
原文链接;http://www.ido321.com/375.html Jquery UI是一个非常丰富的Jquery插件,而且UI的各部分插件能够独自分离出来使用.这是其它非常多Jquery插件没有 ...
- Android 用ping的方法判断当前网络是否可用
判断网络的情况中,有个比较麻烦的情况就是连上了某个网络,但是那个网络无法上网 ,,, = = 想到了用ping指令来判断,经测试,可行~ ~ ~ private static final boolea ...
- How to configure Gzip for JBoss?---refer
Question: I think to try to speed up my Web App by reducing the size of transferred data. For exampl ...
- Android 百度地图 SDK v3.0.0 (四) 引入离线地图功能
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/37758097 一直觉得地图应用支持离线地图很重要啊,我等移动2G屌丝,流量不易, ...
- Ambari安装
给hadoop用户sudo权限 hadoop ALL=(ALL) NOPASSWD:ALL 建立SSH互信,参考Hadoop HA的搭建中的互信建立 建立相应的下载脚本down.sh nohup wg ...
- ado.net(1)
connection对象处于最顶层,是所有数据请求的关口 数据库连接过程 SqlConnection theConnection = new SqlConnection(); //创建一个connec ...
- TreeView绑定无限层级关系类
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Bind_TV(TreeView1.Nodes); ...
- 母函数&&排列(模板)
#include <iostream> #include <algorithm> using namespace std; int main() { int n,i; int ...