zoukankan      html  css  js  c++  java
  • Excel不同表格间复制的问题

    如果要在不同表格间复制worksheet,前提必须是同一个workbooks打开的,否则会报0x800A03EC的错误。

                bool vFG = true;

                m_App.Visible = false;
                //m_App1.Visible = false;

                m_App.DisplayAlerts = false;
                //m_App1.DisplayAlerts = false;

                Workbooks vWorkbooks = m_App.Application.Workbooks;
                //Workbooks vWorkbooks1 = m_App1.Application.Workbooks;

                object vReadOnly = false;
                object vEditable = true;


       Workbook vWorkbook = vWorkbooks.Open( pFileName, m_Missing, vReadOnly, m_Missing, m_Missing, m_Missing, m_Missing, m_Missing, m_Missing, vEditable, m_Missing, m_Missing, m_Missing, m_Missing,m_Missing);

                bool vExist = false;

                for (int i = 1; i <= vWorkbook.Worksheets.Count; i++)
                {
                    Worksheet vWorksheet = (Worksheet)vWorkbook.Worksheets[i];
                    if (vWorksheet.Name.Equals("B票"))
                    {
                        vExist = true;
                        break;
                    }
                }

                if (!vExist)
                {
                    if (this.m_WorkSheetOfMode == null)
                    {

                        Workbook vWorkbook1 = vWorkbooks.Open(this.txtModeOfBugList.Text, m_Missing, vReadOnly, m_Missing, m_Missing, m_Missing, m_Missing, m_Missing, m_Missing, vEditable, m_Missing, m_Missing, m_Missing, m_Missing,m_Missing);

                        Worksheet vWorksheet1 = null;

                        for (int i = 1; i <= vWorkbook1.Worksheets.Count; i++)
                        {
                            vWorksheet1 = (Worksheet)vWorkbook1.Worksheets[i];
                            if (vWorksheet1.Name.Equals("B票"))
                            {
                                vExist = true;

                                this.m_WorkSheetOfMode = vWorksheet1;

                                break;
                            }
                        }

                        if (!vExist)
                        {
                            vFG = false;
                        }
                        else
                        {
                            Worksheet vWorksheet2 = (Worksheet)vWorkbook.Worksheets[vWorkbook.Worksheets.Count];
                           
                            vWorksheet1.Copy(m_Missing, vWorksheet2);
                        }
                    }
                    else
                    {
                        Worksheet vWorksheet2 = (Worksheet)vWorkbook.Worksheets[vWorkbook.Worksheets.Count];
                        this.m_WorkSheetOfMode.Copy(m_Missing, vWorksheet2);
                    }
                }

                vWorkbook.Save();
                //vWorkbooks1[1].Save();

                vWorkbooks.Close();

                vWorkbooks = null;

                //vWorkbooks1.Close();
                m_App.Quit();
                //m_App1.Quit();

  • 相关阅读:
    python如何打开一个大文件?
    python中的多进程与多线程(二)
    python中的多进程与多线程(一)
    python中的深拷贝与浅拷贝
    2018 pycharm最近激活码
    python中的新式类与旧式类
    用python优雅打开文件及上下文管理协议
    解决Mac上安装mysqlclient的错误
    用python实现一个简单的服务器
    高阶函数
  • 原文地址:https://www.cnblogs.com/si812cn/p/1315022.html
Copyright © 2011-2022 走看看