zoukankan
html css js c++ java
读写EXCEL的例子
private
void
process1()
{
if
(
this
.textBox_database.Text
==
""
)
{
MessageBox.Show(
"
请选择导入数据库!
"
,
"
系统信息
"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
return
;
}
if
(
this
.textBox_moban.Text
==
""
)
{
MessageBox.Show(
"
请选择模版文件!
"
,
"
系统信息
"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
return
;
}
if
(
this
.textBox_out.Text
==
""
)
{
MessageBox.Show(
"
请选择输出路径!
"
,
"
系统信息
"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
return
;
}
string
str1
=
"
InterRoll
"
;
string
str2
=
"
FileContent
"
;
this
.readdata(
this
.textBox_database.Text, str1,
"
FileRollNo
"
);
//
案卷题名数据库,以案卷号排序
//
this.readdata(this.textBox_database.Text, str2, "FileNo");
//
内容项数据库,以案卷号排序
//
遍历题名数据库
int
count1
=
this
.dataSet1.Tables[str1].Rows.Count;
this
.richTextBox1.SelectionColor
=
Color.Blue;
this
.richTextBox1.AppendText(
"
案卷分目录生成开始:\n
"
);
if
(Directory.Exists(
this
.textBox_out.Text))
{
Directory.CreateDirectory(
this
.textBox_out.Text);
}
for
(
int
i
=
0
; i
<
count1; i
++
)
{
string
[] head
=
new
string
[
this
.dataSet1.Tables[str1].Rows[i].ItemArray.Length];
//
案卷分目录题名
for
(
int
k
=
0
; k
<
this
.dataSet1.Tables[str1].Rows[i].ItemArray.Length; k
++
)
{
head[k]
=
this
.dataSet1.Tables[str1].Rows[i].ItemArray[k].ToString();
}
string
FileNo1
=
head[
1
].Trim();
string
seach
=
"
seach1
"
;
this
.searchdata(
this
.textBox_database.Text, str2,
"
FileNo = '
"
+
FileNo1
+
"
'
"
, seach);
int
count2
=
this
.dataSet1.Tables[seach].Rows.Count;
string
fileName
=
this
.textBox_moban.Text;
if
(count2
!=
0
)
{
int
finger
=
count2;
//
15行的循环计数标示
int
line
=
0
;
//
当前行
Excel.ApplicationClass excelApp
=
new
Excel.ApplicationClass();
//
Make Excel Visible
excelApp.Visible
=
false
;
//
excelApp.Visible = true;
Excel.Workbook workbook
=
excelApp.Workbooks.Open(fileName,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
Excel.Range range3;
int
xx
=
3
;
//
excel文件的行列
int
yy
=
6
;
object
[,] array3;
int
line_count
=
15
;
FLAG:
if
(finger
>
line_count)
{
array3
=
new
object
[
4
,
8
];
Excel._Worksheet worksheet
=
(Excel._Worksheet)workbook.Worksheets.get_Item(
1
);
range3
=
worksheet.get_Range(
"
A
"
+
xx.ToString(),
"
H
"
+
yy.ToString());
array3[
0
,
0
]
=
"
案卷题名
"
;
array3[
0
,
1
]
=
head[
2
];
//
案卷题名
array3[
0
,
4
]
=
"
档 号
"
;
array3[
0
,
5
]
=
""
;
//
档号(案卷号)
array3[
1
,
4
]
=
"
编 制 日 期
"
;
array3[
1
,
5
]
=
head[
3
];
//
编制日期
array3[
2
,
4
]
=
"
保 管 期 限
"
;
array3[
2
,
5
]
=
"
永久
"
;
//
array3[3, 4] = "共 xx 册 第 nn 册";
array3[
3
,
4
]
=
"
共
"
+
count1.ToString()
+
"
册 第
"
+
(i
+
1
).ToString()
+
"
册
"
;
range3.Value2
=
array3;
xx
+=
5
;
yy
+=
line_count
+
1
;
array3
=
new
object
[line_count,
8
];
worksheet
=
(Excel._Worksheet)workbook.Worksheets.get_Item(
1
);
range3
=
worksheet.get_Range(
"
A
"
+
xx.ToString(),
"
H
"
+
yy.ToString());
for
(
int
mm
=
0
; mm
<
line_count; mm
++
)
{
for
(
int
nn
=
0
; nn
<
8
; nn
++
)
{
array3[mm, nn]
=
""
;
}
}
for
(
int
mm
=
0
; mm
<
line_count; mm
++
)
{
/**/
/*
array3[0, 0] = "顺序号";
array3[0, 1] = "文 件 编 号";
array3[0, 2] = "责任者";
array3[0, 3] = "文 件 材 料 题 名";
array3[0, 5] = "日 期";
array3[0, 6] = "页 次";
array3[0, 7] = "备 注";
*/
array3[mm,
0
]
=
this
.dataSet1.Tables[seach].Rows[line
+
mm].ItemArray[
2
].ToString().Trim();
array3[mm,
1
]
=
this
.dataSet1.Tables[seach].Rows[line
+
mm].ItemArray[
3
].ToString().Trim();
array3[mm,
2
]
=
this
.dataSet1.Tables[seach].Rows[line
+
mm].ItemArray[
4
].ToString().Trim();
array3[mm,
3
]
=
this
.dataSet1.Tables[seach].Rows[line
+
mm].ItemArray[
5
].ToString().Trim();
array3[mm,
5
]
=
this
.dataSet1.Tables[seach].Rows[line
+
mm].ItemArray[
6
].ToString().Trim();
array3[mm,
6
]
=
this
.dataSet1.Tables[seach].Rows[line
+
mm].ItemArray[
7
].ToString().Trim();
array3[mm,
7
]
=
this
.dataSet1.Tables[seach].Rows[line
+
mm].ItemArray[
8
].ToString().Trim();
}
range3.Value2
=
array3;
line
+=
line_count;
finger
-=
line_count;
xx
+=
17
;
yy
+=
6
;
goto
FLAG;
}
else
{
array3
=
new
object
[
4
,
8
];
Excel._Worksheet worksheet
=
(Excel._Worksheet)workbook.Worksheets.get_Item(
1
);
range3
=
worksheet.get_Range(
"
A
"
+
xx.ToString(),
"
H
"
+
yy.ToString());
array3[
0
,
0
]
=
"
案卷题名
"
;
array3[
0
,
1
]
=
head[
2
];
//
案卷题名
array3[
0
,
4
]
=
"
档 号
"
;
array3[
0
,
5
]
=
""
;
//
档号(案卷号)
array3[
1
,
4
]
=
"
编 制 日 期
"
;
array3[
1
,
5
]
=
head[
3
];
//
编制日期
array3[
2
,
4
]
=
"
保 管 期 限
"
;
array3[
2
,
5
]
=
"
永久
"
;
//
array3[3, 4] = "共 xx 册 第 nn 册";
array3[
3
,
4
]
=
"
共
"
+
count1.ToString()
+
"
册 第
"
+
(i
+
1
).ToString()
+
"
册
"
;
range3.Value2
=
array3;
xx
+=
5
;
yy
+=
line_count;
array3
=
new
object
[line_count,
8
];
worksheet
=
(Excel._Worksheet)workbook.Worksheets.get_Item(
1
);
range3
=
worksheet.get_Range(
"
A
"
+
xx.ToString(),
"
H
"
+
yy.ToString());
for
(
int
mm
=
0
; mm
<
15
; mm
++
)
{
for
(
int
nn
=
0
; nn
<
8
; nn
++
)
{
array3[mm, nn]
=
""
;
}
}
for
(
int
mm
=
0
; mm
<
finger; mm
++
)
{
array3[mm,
0
]
=
this
.dataSet1.Tables[seach].Rows[line
+
mm].ItemArray[
2
].ToString().Trim();
array3[mm,
1
]
=
this
.dataSet1.Tables[seach].Rows[line
+
mm].ItemArray[
3
].ToString().Trim();
array3[mm,
2
]
=
this
.dataSet1.Tables[seach].Rows[line
+
mm].ItemArray[
4
].ToString().Trim();
array3[mm,
3
]
=
this
.dataSet1.Tables[seach].Rows[line
+
mm].ItemArray[
5
].ToString().Trim();
array3[mm,
5
]
=
this
.dataSet1.Tables[seach].Rows[line
+
mm].ItemArray[
6
].ToString().Trim();
array3[mm,
6
]
=
this
.dataSet1.Tables[seach].Rows[line
+
mm].ItemArray[
7
].ToString().Trim();
array3[mm,
7
]
=
this
.dataSet1.Tables[seach].Rows[line
+
mm].ItemArray[
8
].ToString().Trim();
}
range3.Value2
=
array3;
line
+=
line_count;
finger
=
0
;
xx
+=
17
;
//
表格指向最后一行
yy
+=
2
;
}
//
删除多余的表格,
Excel._Worksheet worksheet2
=
(Excel._Worksheet)workbook.Worksheets.get_Item(
1
);
range3
=
worksheet2.get_Range(
"
A
"
+
xx.ToString(),
"
H484
"
);
//
range3.Clear();
range3.Delete(Missing.Value);
//
excel 2000/xp
string
savename
=
this
.textBox_out.Text
+
"
\\
"
+
FileNo1
+
"
.xls
"
;
if
(File.Exists(savename))
{
File.Delete(savename);
}
workbook._SaveAs(savename, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Excel.XlSaveAsAccessMode.xlNoChange,
Missing.Value, Missing.Value, Missing.Value, Missing.Value);
workbook.Saved
=
true
;
workbook.Close(Missing.Value, Missing.Value, Missing.Value);
excelApp.UserControl
=
false
;
excelApp.Quit();
this
.richTextBox1.SelectionColor
=
Color.Green;
this
.richTextBox1.AppendText(
"
案卷号:
"
+
FileNo1
+
"
添加成功!\n
"
);
}
else
{
this
.richTextBox1.SelectionColor
=
Color.Red;
this
.richTextBox1.AppendText(
"
案卷号:
"
+
FileNo1
+
"
对应的内容项不存在!\n
"
);
}
}
this
.richTextBox1.SelectionColor
=
Color.Blue;
this
.richTextBox1.AppendText(
"
案卷分目录生成成功!\n
"
);
}
查看全文
相关阅读:
2、selinux服务的操作
1、添加nginx到全局变量中
linux每日命令(1):which
QT重载基类绘制函数并在基类绘制结果基础上进行子类的绘制
QT信号槽无法正常通信的原因
mapgis6.7+加密狗+二次开发SDK库
KMP算法参考及C语言实现
elastic search
RabbitMq docker集群
RabbitMq安装
原文地址:https://www.cnblogs.com/dreign/p/576090.html
最新文章
vuex-pathify 一个基于vuex进行封装的 vuex助手语法插件
你不知道的JavaScript 观后收获
vuecli开启js代码压缩 以及代码分割
uniapp 减小包体积,同样适用vue项目 在vuecli中使用 @fullhuman/postcss-purgecss 达到去除多余css样式
JUC中的阻塞队列
ConcurrentHashMap源码分析
数字签名是什么
密码学相关概念基础
CountDownLatch,Semaphore,CyclicBarrier使用
Condition分析
热门文章
Thread.sleep、Object.wait、LockSupport.park 区别
ReentrantLock 分析
volatile、JMM、内存屏障
synchronized 学习,偏向锁,轻量级锁,重量级锁介绍
如何使用servlet访问mysql数据库
java使用泛型实现Bean类和Map的相互转换
java实现Bean类和Map的相互转换
Docker容器跨主机通信之:直接路由方式
nagios介绍和安装
3、centos6.*与centos7.*防火墙操作命令
Copyright © 2011-2022 走看看