首页 / C# / C# 操作excel基础方法
C# 操作excel基础方法
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了C# 操作excel基础方法,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1520字,纯文字阅读大概需要3分钟。
内容图文
![C# 操作excel基础方法](/upload/InfoBanner/zyjiaocheng/596/139ff39c9db84f25b690a989d51c33d2.jpg)
直接上代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ClosedXML.Excel;
namespace cwexcel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
XLWorkbook g_wb = new XLWorkbook();
private void button1_Click(object sender, EventArgs e)
{
g_wb.AddWorksheet("mysheet01");
g_wb.SaveAs(@"D:\GOPATH\src\wei.com\cwexcel\123.xlsx");
}
private void button2_Click(object sender, EventArgs e)
{
XLWorkbook g_wb = new XLWorkbook(@"D:\GOPATH\src\wei.com\cwexcel\123.xlsx");
IXLWorksheet sheet = g_wb.Worksheet(1);
sheet.Cell(Convert.ToInt32(textBox1.Text),Convert.ToInt32(textBox2.Text)).Value=textBox3.Text;
g_wb.Save();
}
private void button3_Click(object sender, EventArgs e)
{
XLWorkbook g_wb = new XLWorkbook(@"D:\GOPATH\src\wei.com\cwexcel\123.xlsx");
IXLWorksheet sheet = g_wb.Worksheet(1);
g_wb.AddWorksheet();
sheet.Delete();
g_wb.Save();
}
private void button4_Click(object sender, EventArgs e)
{
XLWorkbook g_wb = new XLWorkbook(@"D:\GOPATH\src\wei.com\cwexcel\123.xlsx");
IXLWorksheet sheet = g_wb.Worksheet(1);
sheet.Cell(Convert.ToInt32(textBox1.Text), Convert.ToInt32(textBox2.Text)).Value = textBox3.Text;
sheet.Cell(Convert.ToInt32(textBox1.Text), Convert.ToInt32(textBox2.Text)).Style.Fill.BackgroundColor = XLColor.Blue;
sheet.Cell(Convert.ToInt32(textBox1.Text), Convert.ToInt32(textBox2.Text)).Style.Font.FontColor = XLColor.Red;
g_wb.Save();
}
}
}
内容总结
以上是互联网集市为您收集整理的C# 操作excel基础方法全部内容,希望文章能够帮你解决C# 操作excel基础方法所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。