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); } } }
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); } }
private void DeleteComponentThenImportFresh(IVbComponentDecorator component, string importFile) { vbComponentIo.DeleteComponentFromWorkbook(_workbook, component); vbComponentIo.ImportComponentFromFile(_workbook, importFile); }
public void ExportCodeToFile(IVbComponentDecorator component, string filePath) { component.RawComponent.Export(filePath); }
public int CountCodeLines(IVbComponentDecorator component) { return(component.RawComponent.CodeModule.CountOfLines); }
public void DeleteVbCodeLines(IVbComponentDecorator component, int numberOfLines) { component.RawComponent.CodeModule.DeleteLines(1, numberOfLines); }
public string GetVbCodeLines(IVbComponentDecorator component, int numberOfLines) { return(component.RawComponent.CodeModule.Lines[1, numberOfLines]); }
public void ImportComponentCodeFromFile(IVbComponentDecorator component, string inputFilePath) { component.RawComponent.CodeModule.AddFromFile(inputFilePath); }
public void DeleteComponentFromWorkbook(Workbook workbook, IVbComponentDecorator component) { workbook.VBProject.VBComponents.Remove(component.RawComponent); }
public void DeleteAllCodeFromComponent(IVbComponentDecorator component) { DeleteVbCodeLines(component, CountCodeLines(component)); }