Beispiel #1
0
        private void CleanupComponentAfterImport(IVbComponentDecorator component)
        {
            VbComponentType componentType = component.ComponentType;
            string          headerText;

            if (componentType == VbComponentType.ClassModule || componentType == VbComponentType.Sheet)
            {
                // Delete header lines in sheets and classes
                headerText = vbComponentIo.GetVbCodeLines(component, 4);
                if (headerText.ToLower() == "VERSION 1.0 CLASS\r\nBEGIN\r\n  MultiUse = -1  'True\r\nEnd".ToLower())
                {
                    vbComponentIo.DeleteVbCodeLines(component, 4);
                }
            }
            if (componentType == VbComponentType.UserForm)
            {
                // Delete header lines in forms
                headerText = vbComponentIo.GetVbCodeLines(component, 10);
                if (headerText.StartsWith("version 5#\r\nbegin {", StringComparison.OrdinalIgnoreCase) &&
                    headerText.EndsWith("end", StringComparison.OrdinalIgnoreCase))
                {
                    vbComponentIo.DeleteVbCodeLines(component, 10);
                }
            }
        }
Beispiel #2
0
        private void ClearAllCodeThenImportAsText(IVbComponentDecorator component, string importFile)
        {
            // Delete all lines in existing code
            vbComponentIo.DeleteAllCodeFromComponent(component);

            // Load new code
            vbComponentIo.ImportComponentCodeFromFile(component, importFile);

            // Cleanup code after import
            CleanupComponentAfterImport(component);
        }
        public string GetComponentExportName(IVbComponentDecorator component)
        {
            VbComponentType componentType = component.ComponentType;
            string          componentName = component.Name;

            if (componentType == VbComponentType.Sheet && componentName != ThisWorkbookComponentName)
            {
                return(componentName + SheetNameSeparatorString + component.PrettyName + componentType.FileExt);
            }
            else
            {
                return(componentName + componentType.FileExt);
            }
        }
Beispiel #4
0
 private void DeleteComponentThenImportFresh(IVbComponentDecorator component, string importFile)
 {
     vbComponentIo.DeleteComponentFromWorkbook(_workbook, component);
     vbComponentIo.ImportComponentFromFile(_workbook, importFile);
 }
Beispiel #5
0
 public void ExportCodeToFile(IVbComponentDecorator component, string filePath)
 {
     component.RawComponent.Export(filePath);
 }
Beispiel #6
0
 public int CountCodeLines(IVbComponentDecorator component)
 {
     return(component.RawComponent.CodeModule.CountOfLines);
 }
Beispiel #7
0
 public void DeleteVbCodeLines(IVbComponentDecorator component, int numberOfLines)
 {
     component.RawComponent.CodeModule.DeleteLines(1, numberOfLines);
 }
Beispiel #8
0
 public string GetVbCodeLines(IVbComponentDecorator component, int numberOfLines)
 {
     return(component.RawComponent.CodeModule.Lines[1, numberOfLines]);
 }
Beispiel #9
0
 public void ImportComponentCodeFromFile(IVbComponentDecorator component, string inputFilePath)
 {
     component.RawComponent.CodeModule.AddFromFile(inputFilePath);
 }
Beispiel #10
0
 public void DeleteComponentFromWorkbook(Workbook workbook, IVbComponentDecorator component)
 {
     workbook.VBProject.VBComponents.Remove(component.RawComponent);
 }
Beispiel #11
0
 public void DeleteAllCodeFromComponent(IVbComponentDecorator component)
 {
     DeleteVbCodeLines(component, CountCodeLines(component));
 }