如果要将文本插入一个.txt文件,可以用
StreamWriter sw=File.AppendText("文本文件路径");
sw.WriteLine("插入的文本" ,System.Text.Encoding.GetEncoding("Gb2312"));
sw.Close();但是如果要插入到一个Excel文件末尾下一行的第一列呢?

解决方案 »

  1.   

    用oledb打开excel文件,得到工作表中总行数count
    然后在count+1行写
      

  2.   

    public void CloseExcel()
        {        if (m_oBook != null)
                m_oBook.Close(false, m_oMissing, m_oMissing); // true, m_sReportTemplate, m_oMissing        // Quit Excel and clean up.
    if (m_oRange != null)
    System.Runtime.InteropServices.Marshal.ReleaseComObject(m_oRange);
    m_oRange = null;
            if (m_oSheet != null)
                System.Runtime.InteropServices.Marshal.ReleaseComObject(m_oSheet);
            m_oSheet = null;
            if (m_oBook != null)
                System.Runtime.InteropServices.Marshal.ReleaseComObject(m_oBook);
            m_oBook = null;
            if (m_oBooks != null)
                System.Runtime.InteropServices.Marshal.ReleaseComObject(m_oBooks);
            m_oBooks = null;
            if (m_oExcelApp != null)
            {
                m_oExcelApp.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(m_oExcelApp);
                m_oExcelApp = null;
            }
             GC.Collect ();
     GC.WaitForPendingFinalizers();
        }
      

  3.   

    http://linfuguo.cnblogs.com/archive/2006/03/23/357155.html
      

  4.   

    我定义了这些对象:
    Excel.Application excel;
    Excel._Workbook xBk;
    Excel._Worksheet xSt;
    Excel._QueryTable xQt;要关闭当前Excel,需要一个个对象关闭?还是直接关闭excel对象?还是其它方法?
    怎么关闭?