Excel技巧教程:不同表格间复制的问题

发布: 2009-2-16 19:14  作者: 网络转载  查看: 1105次 共有0条评论

:不同间复制的问题

  如果要在不同表格间复制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;
       (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();

相关阅读
大家对 Excel技巧教程:不同表格间复制的问题 的评论
最新PPT教程
最新评论
PPT问答