社区
C#
帖子详情
C# 怎么操作Excel啊?
zenkishi
2006-05-08 02:01:45
网上东东太乱了。各位大虾能提供基础一点的东西吗?
...全文
241
5
打赏
收藏
C# 怎么操作Excel啊?
网上东东太乱了。各位大虾能提供基础一点的东西吗?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
葫芦鬼
2006-05-08
打赏
举报
回复
using Excel = Microsoft.Office.Interop.Excel;
using OleColor = System.Drawing.ColorTranslator;
{
private Excel.Application m_excelApp = null;
public InitExcel()
{
Excel.Workbook book = m_excelApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
Excel.Worksheet firstSheet = (Excel.Worksheet)book.ActiveSheet;
firstSheet.Name = "FirstSheet";
Excel.Range range = firstSheet.get_Range("A1", "F5");
for(int i = 1; i < 5; ++i)
{
for(int j = 1; j < 5; ++j)
{
if(i != j)
continue;
Excel.Range subRange = range.Cells[i, j] as Excel.Range;
subRange.Value2 = i.ToString();
subRange.Font.Color = OleColor.ToOle(Color.Blue);
subRange.Interior.Color = OleColor.ToOle(Color.Brown);
}
}
Excel.Worksheet secondSheet = (Excel.Worksheet)book.Worksheets.Add(m_Miss, book.Worksheets[book.Worksheets.Count], m_Miss, m_Miss);
firstSheet.Name = "SecondSheet";
range = secondSheet.get_Range("A1", "F5");
for(int i = 1; i < 5; ++i)
{
for(int j = 1; j < 5; ++j)
{
if(i != j)
continue;
Excel.Range subRange = range.Cells[i, j] as Excel.Range;
subRange.Value2 = i.ToString();
subRange.Font.Color = OleColor.ToOle(Color.Black);
subRange.Interior.Color = OleColor.ToOle(Color.Red);
}
}
Excel.Worksheet thirdSheet = (Excel.Worksheet)book.Worksheets.Add(m_Miss, book.Worksheets[book.Worksheets.Count], m_Miss, m_Miss);
thirdSheet.Name = "ThirdSheet";
firstSheet.UsedRange.Copy(thirdSheet.get_Range("A1","A1"));
secondSheet.UsedRange.Copy(thirdSheet.get_Range("A6","A6"));
range = thirdSheet.get_Range("A10","D10");
range.Value2 = m_excelApp.Path;
range.Cells.MergeCells = true;
range = thirdSheet.get_Range("C13","D13");
range.Cells.Value2 = "C12, D12";
range.Cells.Font.Color = OleColor.ToOle(Color.Black);
range.Interior.Color = OleColor.ToOle(Color.White);
range = range.get_Offset(2,2);
range.Cells.Value2 = "B15, C15";
range.Cells.Font.Color = OleColor.ToOle(Color.Black);
range.Interior.Color = OleColor.ToOle(Color.Turquoise);
range = thirdSheet.get_Range("C13","D13");
range.get_Offset(-2, -2);
range.Cells.Value2 = "C11, D11";
range.Cells.Font.Color = OleColor.ToOle(Color.Black);
range.Interior.Color = OleColor.ToOle(Color.Turquoise);
firstSheet.Activate();
m_excelApp.Visible = true;
}
}
葫芦鬼
2006-05-08
打赏
举报
回复
现成的代码我也有 不是不想给你
在看过MSDN后 我说的方法对你是最有帮助的
lishaowensdut
2006-05-08
打赏
举报
回复
.net里面有例子
zenkishi
2006-05-08
打赏
举报
回复
怎么这么敷衍!
葫芦鬼
2006-05-08
打赏
举报
回复
自己在Excel里录个宏来看看就明白了
C#
对
excel
的
操作
C#
对
excel
的
操作
C#
对
excel
的
操作
C#
对
excel
的
操作
C#
对
excel
的
操作
C#
对
excel
的
操作
C#
对
excel
的
操作
C#
对
excel
的
操作
C#
对
excel
的
操作
C#
对
excel
的
操作
C#
对
excel
的
操作
C#
对
excel
的
操作
C#
操作
Excel
写数据生成图表
C#
的,winform的,这是我自己写的一个
c#
操作
excel
的例子,其中包括数据
操作
,字体,格式,单元格等
操作
,还有一个生成柱状图的方法,所有的方法都在
Excel
Helper.cs类里,点击Form1窗体里的按钮可以看到各种
操作
的...
Python
操作
Excel
(openpyxl版)
课程简介: openpyxl模块是一个读写
Excel
2010及以上版本文档的...原因看下面的图 本课程的主要内容: openpyxl的基础
操作
(关于workbook、sheet、行列、格式设置等) 一些典型案例 与图表相关的
操作
其他高级
操作
C#
操作
Excel
C#
操作
Excel
的方法
C#
操作
excel
打开-读取-修改-保存 winform入门
操作
C#
操作
excel
打开-读取-修改-保存 winform入门
操作
适合入门读者
C#
110,533
社区成员
642,574
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章