📄 1.mht
字号:
=C8=A1=B5=C3=D7=DC=BC=C7=C2=BC=CA=FD=B8=FA=BF=C9=B7=D6=B3=C9=BC=B8=B8=F6E=
xcel sheet.<BR> ///=20
</summary><BR> /// =
<param=20
=
name=3D"strTableName">=B1=BB=B2=E9=D1=AF=B5=C4=CA=FD=BE=DD=BF=E2=B5=C4=
=B1=ED=C3=FB</param><BR> =
/// <param=20
=
name=3D"sqlConn">sqlConnection</param><BR> &nbs=
p; =20
/// <returns>=BF=C9=B7=D6=B3=C9Excel=20
=
Sheet=B5=C4=B8=F6=CA=FD</returns><BR> =
private=20
int GetTotalSize(string strTableName,SqlConnection=20
sqlConn)<BR> =20
=
{<BR> =20
//sqlConn =3D new=20
=
System.Data.SqlClient.SqlConnection(strConnect);<BR> &nb=
sp; =20
sqlCmd =3D new System.Data.SqlClient.SqlCommand("Select Count(*) From=20
"+strTableName,=20
=
sqlConn);<BR> =
=20
if(this.sqlConn.State =3D=3D ConnectionState.Closed)=20
=
sqlConn.Open();<BR> =
=20
dbTotalSize =3D=20
=
(int)sqlCmd.ExecuteScalar();<BR>  =
; =20
=
sqlConn.Close();<BR>  =
; =20
return (int)Math.Ceiling(dbTotalSize /=20
this.dbSheetSize);<BR> }</P>
<P> ///=20
<summary><BR> ///=20
=
=D0=C2=BD=A8=D2=BB=B8=F6Excel=CA=B5=C0=FD<BR> &nbs=
p; ///=20
</summary><BR> /// =
<param=20
=
name=3D"strTitle">Excel=B1=ED=CD=B7=C9=CF=B5=C4=CE=C4=D7=D6</param&=
gt;<BR> =20
public void DeclareExcelApp(string[] strTitle,string strSql,string=20
strTableName,string=20
strMastTitle)<BR> =20
=
{<BR> =20
m_objExcel =3D new=20
=
Excel.ApplicationClass();<BR> &n=
bsp; =20
m_objExcel.Visible =3D=20
=
true;<BR> &nbs=
p;=20
m_objBooks =3D=20
=
(Excel.Workbooks)m_objExcel.Workbooks;<BR> &=
nbsp; =20
m_objBook =3D=20
=
(Excel._Workbook)(m_objBooks.Add(m_objOpt));<BR> &=
nbsp; =20
m_objSheets =3D=20
=
(Excel.Sheets)m_objBook.Worksheets;<BR> &nbs=
p; =20
if (intSheetTotalSize <=3D=20
=
3)<BR> =
=
{<BR> &n=
bsp; =20
if (this.dbTotalSize <=3D=20
=
this.dbSheetSize)<BR> &nbs=
p; =20
=
{<BR> &n=
bsp; =20
this.ExportDataByQueryTable(1, =
false,strTitle,strSql,strTableName,strMastTitle=20
=
);<BR> &=
nbsp; =20
=
return;<BR> &n=
bsp; =20
=
}<BR> &n=
bsp; =20
else if (this.dbTotalSize <=3D this.dbSheetSize *=20
=
2)<BR> &=
nbsp; =20
=
{<BR> &n=
bsp; =20
this.ExportDataByQueryTable(1, =
false,strTitle,strSql,strTableName,strMastTitle=20
=
);<BR> &=
nbsp; =20
this.ExportDataByQueryTable(2, =
true,strTitle,strSql,strTableName,strMastTitle=20
=
);<BR> &=
nbsp; =20
=
return;<BR> &n=
bsp; =20
=
}<BR> &n=
bsp; =20
=
else<BR>  =
; =20
=
{<BR> &n=
bsp; =20
this.ExportDataByQueryTable(1, =
false,strTitle,strSql,strTableName,strMastTitle=20
=
);<BR> &=
nbsp; =20
this.ExportDataByQueryTable(2, =
true,strTitle,strSql,strTableName,strMastTitle=20
=
);<BR> &=
nbsp; =20
this.ExportDataByQueryTable(3, =
true,strTitle,strSql,strTableName,strMastTitle=20
=
);<BR> &=
nbsp; =20
=
return;<BR> &n=
bsp; =20
=
}<BR> =20
=
}<BR> =
for=20
(int i =3D 3; i < intSheetTotalSize;=20
=
i++)<BR>  =
;=20
=
{<BR> &n=
bsp; =20
m_objSheets.Add(m_objOpt, m_objSheets.get_Item(i), m_objOpt,=20
=
m_objOpt);<BR>  =
; =20
=
}<BR> =20
ExportDataByQueryTable(1, =
false,strTitle,strSql,strTableName,strMastTitle=20
=
);<BR> =
for=20
(int i =3D 2; i <=3D m_objSheets.Count;=20
=
i++)<BR>  =
;=20
=
{<BR> &n=
bsp; =20
ExportDataByQueryTable(i, =
true,strTitle,strSql,strTableName,strMastTitle=20
=
);<BR> =
}<BR> =20
}<BR> ///=20
<summary><BR> ///=20
=
=D2=D4=D3=C3=BB=A7=CA=E4=C8=EB=B5=C4=CE=C4=BC=FE=C3=FB=B1=A3=B4=E6=CE=C4=BC=
=FE<BR> ///=20
</summary><BR> public =
void=20
SaveExcelApp()<BR> =20
=
{<BR> =
string=20
excelFileName =3D=20
=
string.Empty;<BR> &n=
bsp; =20
SaveFileDialog sf =3D new=20
=
SaveFileDialog();<BR> &nbs=
p; =20
sf.Filter =3D=20
=
"*.xls|*.*";<BR> &nb=
sp; =20
if (sf.ShowDialog() =3D=3D=20
=
DialogResult.OK)<BR>  =
; =20
=
{<BR> &n=
bsp; =20
excelFileName =3D=20
=
sf.FileName;<BR> &nb=
sp; =20
=
}<BR> =20
=
else<BR>  =
;=20
=
{<BR> &n=
bsp; =20
=
return;<BR> &n=
bsp;=20
=
}<BR> =20
m_objBook.SaveAs(excelFileName, m_objOpt, m_objOpt, m_objOpt, =
m_objOpt,=20
m_objOpt,=20
=
<BR> &nb=
sp; =20
Excel.XlSaveAsAccessMode.xlNoChange, m_objOpt, m_objOpt, m_objOpt,=20
=
m_objOpt,m_objOpt);<BR> &n=
bsp; =20
if (m_objExcel !=3D=20
=
null)<BR> &nbs=
p; =20
m_objExcel =3D null;<BR> =20
}<BR> ///=20
<summary><BR> ///=20
=
=C0=FB=D3=C3Excel=B5=C4QueryTable=B5=BC=B3=F6=CA=FD=BE=DD<BR> =
///=20
</summary><BR> /// =
<param=20
=
name=3D"intSheetNumber">=B5=BC=B3=F6=B5=DA=BC=B8=B8=F6sheet</param&=
gt;<BR> =20
/// <param=20
=
name=3D"blIsMoreThan">=D3=E0=CF=C2=B5=C4=CA=FD=BE=DD=CA=C7=B7=F1=B4=F3=
=D3=DA=D6=B8=B6=A8=B5=C4=C3=BF=B8=F6Sheet=B5=C4=D7=EE=B4=F3=BC=C7=C2=BC=CA=
=FD</param><BR> =20
/// <param=20
=
name=3D"strTitle">=B1=ED=CD=B7,=D0=E8=BA=CD=B2=E9=D1=AFsql=D3=EF=BE=E4=
=B6=D4=C6=EB=D2=BB=D6=C2=A1=A3</param><BR> &=
nbsp; =20
/// <param=20
=
name=3D"strSql">=B2=E9=D1=AF=B5=C4sql=D3=EF=BE=E4=A3=AC=B1=ED=CD=B7=B5=
=C4=CE=C4=D7=D6=D0=E8=BA=CD=B8=C3sql=D3=EF=BE=E4=B6=D4=C6=EB=D2=BB=D6=C2=A1=
=A3</param><BR> =20
/// <param =
name=3D"strTablName">=B2=E9=D1=AF=B5=C4=B1=ED=C3=FB</param> =
; =20
<BR> /// <param=20
=
name=3D"strMastTitle">=D6=F7=B1=EA=CC=E2</param><BR> =
=20
/// </summary><BR> =
public void=20
ExportDataByQueryTable(int intSheetNumber, bool blIsMoreThan,string[]=20
strTitle,string strSql,string strTablName,string=20
strMastTitle)<BR> =20
=
{<BR> =
string=20
strQuery =3D=20
=
string.Empty;<BR> &n=
bsp; =20
if=20
=
(blIsMoreThan)<BR> &=
nbsp; =20
=
{<BR> &n=
bsp; =20
strQuery =3D "Select Top "=20
=
+<BR> &n=
bsp; =20
this.dbSheetSize + strSql + " From " + strTablName + " Where =
Not =20
OrderID In (Select Top "=20
=
+<BR> &n=
bsp; =20
dbSheetSize * (intSheetNumber - 1) + " OrderID From " + =
strTablName +=20
=
")";<BR>  =
;=20
=
}<BR> =20
=
else<BR>  =
;=20
=
{<BR> &n=
bsp; =20
strQuery =3D "Select Top " + this.dbSheetSize + strSql+ " From=20
"+strTablName;</P>
<P> =20
=
}<BR> =20
m_objSheet =3D =
(Excel._Worksheet)(m_objSheets.get_Item(intSheetNumber));</P>
<P> =20
m_objSheet.Cells[1,1] =3D=20
=
strMastTitle;<BR> &n=
bsp; =20
m_objSheet.Cells[2,1] =3D=20
=
"=B4=F2=D3=A1=C8=D5=C6=DA"+DateTime.Now.ToShortDateString();<BR> &nb=
sp; =20
for(int i =3D=20
=
1;i<=3DstrTitle.Length;i++)<BR> &nb=
sp; =20
=
{<BR> &n=
bsp; =20
m_objSheet.Cells[4,i] =3D=20
=
strTitle[i-1].ToString();<BR> &n=
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -