C中数据导出到Excel表格(11)
发布时间:2021-06-07
发布时间:2021-06-07
DataGridView 数据导出到Excel
91.
92. workbooks.Close();
93. if (xlApp != null)
94. {
95. xlApp.Workbooks.Close();
96. xlApp.Quit();
97. int generation = System.GC.GetGeneration(xlApp);
98. System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
99. xlApp = null;
100. System.GC.Collect(generation);
101. }
102. GC.Collect();//强行销毁
103. #region 强行杀死最近打开的Excel进程
104. System.Diagnostics.Process[] excelProc =
System.Diagnostics.Process.GetProcessesByName("EXCEL");
105. System.DateTime startTime = new DateTime();
106. int m, killId = 0;
107. for (m = 0; m < excelProc.Length; m++)
108. {
109. if (startTime < excelProc[m].StartTime)
110. {
111. startTime = excelProc[m].StartTime;
112. killId = m;
113. }
114. }
115. if (excelProc[killId].HasExited == false)
116. {
117. excelProc[killId].Kill();
118. }
119. #endregion
120. MessageBox.Show( "导出成功!" );
121. }
122. }
123. }
上一篇:红楼梦人物描写风格浅析
下一篇:美国联邦制的发展。