2011-09-04 5 views

답변

3

실제 응용 프로그램을 자동화하려고한다고 가정합니다.

에 대한 참조를 추가 확장 라이브러리

응용 프로그램에 대해

  • Microsoft.Office.Interop.Word
  • Microsoft.Office.Interop.Excel
  • Microsoft.Office.Interop.PowerPoint
  • Microsoft.Office.Interop.PowerPoint 마이크로 소프트 Visual Basic에서 다음해야 제거하다 Excel 용 매크로 코드 Word와 PowerPoint를 자동화하는 방법도 비슷합니다.

    using Excel = Microsoft.Office.Interop.Excel; 
    using Word = Microsoft.Office.Interop.Word; 
    using PPT = Microsoft.Office.Interop.PowerPoint; 
    using Microsoft.Vbe.Interop; 
    
    namespace OfficeMacros 
    { 
        class Program 
        { 
         static void Main(string[] args) 
         { 
         } 
    
         static void RemoveMacrosExcel(string fileName, string newFileName) 
         { 
          var excel = new Excel.Application(); 
          var workbook = excel.Workbooks.Open(fileName, 
           Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
           Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
           Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
           Type.Missing, Type.Missing); 
    
          foreach (VBComponent component in workbook.VBProject.VBComponents) 
          { 
           switch (component.Type) 
           { 
            case (vbext_ComponentType.vbext_ct_StdModule): 
            case (vbext_ComponentType.vbext_ct_MSForm): 
            case (vbext_ComponentType.vbext_ct_ClassModule): 
             workbook.VBProject.VBComponents.Remove(component); 
             break; 
            default: 
             component.CodeModule.DeleteLines(1, component.CodeModule.CountOfLines); 
             break; 
           } 
          } 
    
          workbook.Close(true, newFileName, Type.Missing); 
    
          // Release variables 
          workbook = null; 
          excel = null; 
    
          // Collect garbage 
          GC.Collect(); 
         } 
        } 
    } 
    

    당신이 바이너리 파일 구조를 직접 분석 할 경우, 당신은이 문서를 검토해야합니다

    을 그 보인다면 너무 발굴, 훌륭한 라이브러리가 만들어집니다 b y DIaLOGIKab2xtranslator (이진 (doc, xls, ppt) to OpenXMLTranslator). .doc, .xls 및 .ppt에 대한 이진 구조 중 C# 개체에 매핑되는 대부분의 (전부는 아닐지라도) 이진 구조가 있습니다.

    b2xtranslator의 의도는 바이너리 오피스 문서를 최신 OpenXML 형식으로 변환하는 것이지만 라이브러리를 사용하여 문서를 구문 분석하고 매크로 요소를 직접 제거 할 수 있습니다.

+0

+1. 지금 훨씬 더 간단합니다. Microsoft는 수년 전 (95/97 기간)해야 할 때 바이너리 형식의 문서를 얻기 위해 비공개 계약서에 서명해야했습니다. – devstuff

관련 문제