欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
C#導出EXCEL格式

必須先添加COM中的EXCEL引用

如micrsoft.excel.11 ,還有microsoft.office.11

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Excel;
using Microsoft.Office.Core;
using System.IO;
using System.Reflection;

namespace WindowsApplication15
{
    public partial class Form1 : Form
    {
        private object missing = Missing.Value;
        private Excel.Application ExcelRS;
        private Excel.Workbook RSbook;
        private Excel.Worksheet RSsheet;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: 這行代碼將數據加載到表“nSPGDataSet.SWRY”中。您可以根據需要移動(dòng)或移除它。
            this.sWRYTableAdapter.Fill(this.nSPGDataSet.SWRY);
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string OutFilePath = @"c:\lyx1.xls";

            string TemplateFilePath = @"c:\模版.xls";
            PrintInit(TemplateFilePath, OutFilePath);


          

        }


        public void PrintInit(string templetFile, string outputFile)
        {
            try
            {
                if (templetFile == null)
                {
                    MessageBox.Show("Excel模板文件路徑不能為空!");
                 
                }
                if (outputFile == null)
                {
                    MessageBox.Show("輸出Excel文件路徑不能為空!");
                   
                }
                //把模版文件templetFile拷貝到目輸出文件outputFile中,并且目標文件可以改寫(xiě)
                System.IO.File.Copy(templetFile, outputFile, true);
                if (this.ExcelRS != null)
                    ExcelRS = null;
                //實(shí)例化ExcelRS對象
                ExcelRS = new Excel.ApplicationClass();

                if (ExcelRS == null)
                {
                    MessageBox.Show("ERROR:   EXCEL   couldn 't   be   started ");
                }


                //打開(kāi)目標文件outputFile
                RSbook = ExcelRS.Workbooks.Open(outputFile, missing, missing, missing, missing, missing,
                         missing, missing, missing, missing, missing, missing, missing, missing, missing);
                //設置第一個(gè)工作溥
                RSsheet = (Excel.Worksheet)RSbook.Sheets.get_Item(1);
                ////激活當前工作溥
                //RSsheet.Activate();


                for (int i = 0; i < this.dataGridView1.RowCount - 1; i++)
                {
                    // MessageBox.Show(this.dataGridView1[0, i].Value.ToString() + this.dataGridView1[1, i].Value.ToString());
                    RSsheet.Cells[3 + i, 1] = this.dataGridView1[0, i].Value.ToString();
                    RSsheet.Cells[3 + i, 2] = this.dataGridView1[1, i].Value.ToString();

                }

                //保存目標文件
                //RSbook.Save();
                RSbook.Close(true, missing, missing);


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());

            }

            finally
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(RSsheet);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(RSbook);
                //設置DisplayAlerts

                ExcelRS.DisplayAlerts = false;
                ExcelRS.Visible = true;
                //ExcelRS.DisplayAlerts = true;

                //釋放對象
                RSsheet = null;
                RSbook = null;
               
                ExcelRS.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(ExcelRS);
                ExcelRS = null;
                GC.Collect();

 

            }
       }

      

 

    }
}

 


本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Excel操作 Microsoft.Office.Interop.Excel.dll的使用
【轉】教你用C#讀寫(xiě)、刪除、更新excel表格記錄
C# 將數據導出到Excel匯總
JAVA使用hutool poi工具讀取Excel模板并寫(xiě)值輸出文件
C#操作Excel實(shí)現實(shí)例解析
Asp.net常見(jiàn)word excel ppt pdf在線(xiàn)預覽方案
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久