Skip to content

Commit

Permalink
Optimierung Sheet-Änderungen
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaenggli committed Aug 17, 2020
1 parent ef88051 commit f35ad26
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 116 deletions.
4 changes: 2 additions & 2 deletions ExcelAddIn_TableOfContents.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<PublishUrl>\\asyn\web\PlugIn\Excel\</PublishUrl>
<InstallUrl />
<TargetCulture>de</TargetCulture>
<ApplicationVersion>1.0.0.3</ApplicationVersion>
<ApplicationVersion>1.0.0.4</ApplicationVersion>
<AutoIncrementApplicationRevision>true</AutoIncrementApplicationRevision>
<UpdateEnabled>true</UpdateEnabled>
<UpdateInterval>0</UpdateInterval>
Expand Down Expand Up @@ -268,7 +268,7 @@
<FlavorProperties GUID="{BAA0C2D2-18E2-41B9-852F-F413020CAA33}">
<ProjectProperties HostName="Excel" HostPackage="{29A7B9D7-A7F1-4328-8EF0-6B2D1A56B2C1}" OfficeVersion="15.0" VstxVersion="4.0" ApplicationType="Excel" Language="cs" TemplatesPath="" DebugInfoExeName="#Software\Microsoft\Office\16.0\Excel\InstallRoot\Path#excel.exe" DebugInfoCommandLine="/x" AddItemTemplatesGuid="{51063C3A-E220-4D12-8922-BDA915ACD783}" />
<Host Name="Excel" GeneratedCodeNamespace="ExcelAddIn_TableOfContents" PublishedHash="69C324AB27932AA2FBF2B7EA72250886FF164DE6" IconIndex="0">
<HostItem Name="ThisAddIn" Code="ThisAddIn.cs" CanonicalName="AddIn" CanActivate="false" IconIndex="1" Blueprint="ThisAddIn.Designer.xml" GeneratedCode="ThisAddIn.Designer.cs" PublishedHash="DE11528884904ABA78893F8504A87A558B3DF1DF" />
<HostItem Name="ThisAddIn" Code="ThisAddIn.cs" CanonicalName="AddIn" PublishedHash="DE11528884904ABA78893F8504A87A558B3DF1DF" CanActivate="false" IconIndex="1" Blueprint="ThisAddIn.Designer.xml" GeneratedCode="ThisAddIn.Designer.cs" />
</Host>
</FlavorProperties>
</VisualStudio>
Expand Down
8 changes: 0 additions & 8 deletions GlobalFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ class GlobalFunction
{


// 'check whether Excel-GUI is german or not
public static bool isGermanGUI() {
return true;
//ToDo: Sprache ermitteln...
}



//'Does the sheet exists in specific workbook?
public static bool worksheetExists(Excel.Workbook WB, String sheetToFind ) {
foreach (Excel.Worksheet Sheet in WB.Worksheets) {
Expand Down
12 changes: 11 additions & 1 deletion Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
<Value Profile="(Default)">TableStyleMedium15</Value>
</Setting>
<Setting Name="UpdateUrl" Type="System.String" Scope="Application">
<Value Profile="(Default)">https://github.com/ahaenggli/ExcelAddIn_TableOfContents/releases/download/latest/ExcelAddIn_TableOfContents.zip</Value>
<Value Profile="(Default)">https://github.com/ahaenggli/ExcelAddIn_TableOfContents/releases/latest/download/ExcelAddIn_TableOfContents.zip</Value>
</Setting>
<Setting Name="LastUpdateCheck" Type="System.DateTime" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="VersionUrl" Type="System.String" Scope="Application">
<Value Profile="(Default)">https://api.github.com/repos/ahaenggli/ExcelAddIn_TableOfContents/releases/latest</Value>
</Setting>
</Settings>
</SettingsFile>
141 changes: 58 additions & 83 deletions ThisAddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
using System.Net;
using System.Threading;
using System.IO.Compression;
using System.Text;
using System.Text.RegularExpressions;
using System.Reflection;

namespace ExcelAddIn_TableOfContents
{
Expand All @@ -24,10 +27,6 @@ private void ThisAddIn_Startup(object sender, System.EventArgs e)
//event and property do have the same name ....
((Excel.AppEvents_Event)this.Application).NewWorkbook += Application_NewWorkbook;

//event for changes in TOC-Sheet
this.Application.SheetChange += Application_SheetChange;


Thread worker = new Thread(Update);
worker.IsBackground = true;
worker.Start();
Expand Down Expand Up @@ -86,12 +85,13 @@ private void Application_SheetChange(object Sh, Range Target)
string str_arrTblCols = String.Join(";", arrTblCols);
string str_newCusProp = String.Join(";", newCusProp);


PropertyExtension.setProperty(ws, "TocColumns", str_arrTblCols);
PropertyExtension.setProperty(ws, "TocCustomProperties", str_newCusProp);

}

public string Selector(Excel.Range cell)
private string Selector(Excel.Range cell)
{
if (cell.Value2 == null)
return "";
Expand All @@ -106,8 +106,6 @@ private void Application_NewWorkbook(Excel.Workbook Wb)
PropertyExtension.setProperty(Wb.Sheets[1], "isToc", "0");
}



private void Application_WorkbookNewSheet(Excel.Workbook Wb, object Sh)
{
if (!(Sh is Excel.Worksheet)) return;
Expand All @@ -121,63 +119,18 @@ private void Application_SheetActivate(object Sh)
if (!(Sh is Excel.Worksheet)) return;

if (((Excel.Worksheet)Sh).Name.Equals(TocSheetExtension.getTocSheetName()))
{
TocSheetExtension.generateTocWorksheet();

//event for changes in TOC-Sheet
this.Application.SheetChange += Application_SheetChange;
} else this.Application.SheetChange -= Application_SheetChange;
}
private void ThisAddIn_Shutdown(object sender, EventArgs e)
{

}


/*
Option Explicit
'event handler for application
Private TocSheetExtension_AppEventHandler As TocSheetAppEventHandler
' Sub is called whenever AddIn is loaded
Private Sub Workbook_Open()
'To combine keys with Precede the key code by
'SHIFT + (plus sign)
'CTRL ^ (caret)
'ALT % (percent sign)
'' CTRL + Shift + A
'Application.OnKey "^+{A}", "tstBox"
Application.OnKey "{F5}", "handleF5Click"
isF5 = False
'init application wide event handler
Set TocSheetExtension_AppEventHandler = New TocSheetAppEventHandler
End Sub
*/

// handles click on F5-Key
private void handleF5Click()
private void ThisAddIn_Shutdown(object sender, EventArgs e)
{

Excel.Workbook ActiveWorkbook = Globals.ThisAddIn.Application.ActiveWorkbook;

if (ActiveWorkbook == null) return;


if (!ActiveWorkbook.ActiveSheet.Name.Equals(TocSheetExtension.getTocSheetName()))
{
Form frm = new frmPropertyExtension();
frm.Show();
}
else
TocSheetExtension.generateTocWorksheet();



}



private void Update()
{
try
Expand All @@ -188,45 +141,67 @@ private void Update()
Properties.Settings.Default.Save();
}

Version a = Assembly.GetExecutingAssembly().GetName().Version;
Version b = a;

// once a day should be enougth....
if (Settings.Default.LastUpdateCheck.AddMinutes(60) <= DateTime.Now)
if (Settings.Default.LastUpdateCheck.AddHours(1) <= DateTime.Now)
{

string ProgramData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\haenggli.NET\";
string AddInData = ProgramData + @"ExcelAddIn_TableOfContents\";
string StartFile = AddInData + @"ExcelAddIn_TableOfContents.vsto";
string localFile = AddInData + @"ExcelAddIn_TableOfContents.zip";
string DownloadUrl = Environment.GetEnvironmentVariable("TableOfContents_DownloadUrl", EnvironmentVariableTarget.Machine) ?? Settings.Default.UpdateUrl;

if (DownloadUrl.Equals("---"))
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
HttpWebRequest wr = (HttpWebRequest )WebRequest.Create(Settings.Default.VersionUrl);
wr.UserAgent = "ahaenggli/ExcelAddIn_TableOfContents";
var x = wr.GetResponse(); ;

using (var reader = new System.IO.StreamReader(x.GetResponseStream()))
{
Settings.Default.LastUpdateCheck = DateTime.Now;
Properties.Settings.Default.Save();
return;
string json = reader.ReadToEnd();
if (json.Contains("tag_name"))
{
Regex pattern = new Regex("\"tag_name\":\"v\\d+(\\.\\d+){2,}\",");
Match m = pattern.Match(json);
b = new Version(m.Value.Replace("\"", "").Replace("tag_name:v", "").Replace(",", ""));
}
}

if (!Directory.Exists(AddInData)) Directory.CreateDirectory(AddInData);
foreach (System.IO.FileInfo file in new DirectoryInfo(AddInData).GetFiles()) file.Delete();
foreach (System.IO.DirectoryInfo subDirectory in new DirectoryInfo(AddInData).GetDirectories()) subDirectory.Delete(true);

if (DownloadUrl.StartsWith("http"))
if (b > a)
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
WebClient webClient = new WebClient();
webClient.DownloadFile(DownloadUrl, localFile);
webClient.Dispose();
DownloadUrl = localFile;
}

ZipFile.ExtractToDirectory(DownloadUrl, AddInData);

string ProgramData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\haenggli.NET\";
string AddInData = ProgramData + @"ExcelAddIn_TableOfContents\";
string StartFile = AddInData + @"ExcelAddIn_TableOfContents.vsto";
string localFile = AddInData + @"ExcelAddIn_TableOfContents.zip";
string DownloadUrl = Environment.GetEnvironmentVariable("TableOfContents_DownloadUrl", EnvironmentVariableTarget.Machine) ?? Settings.Default.UpdateUrl;

if (DownloadUrl.Equals("---"))
{
Settings.Default.LastUpdateCheck = DateTime.Now;
Properties.Settings.Default.Save();
return;
}

if (!Directory.Exists(AddInData)) Directory.CreateDirectory(AddInData);
foreach (System.IO.FileInfo file in new DirectoryInfo(AddInData).GetFiles()) file.Delete();
foreach (System.IO.DirectoryInfo subDirectory in new DirectoryInfo(AddInData).GetDirectories()) subDirectory.Delete(true);

if (DownloadUrl.StartsWith("http"))
{

WebClient webClient = new WebClient();
webClient.DownloadFile(DownloadUrl, localFile);
webClient.Dispose();
DownloadUrl = localFile;
}

ZipFile.ExtractToDirectory(DownloadUrl, AddInData);
}
Settings.Default.LastUpdateCheck = DateTime.Now;
Properties.Settings.Default.Save();
}
}
catch (System.Exception Ex)
{
MessageBox.Show(Ex.Message);
if(!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("TableOfContents_DownloadUrl", EnvironmentVariableTarget.Machine)))
MessageBox.Show(Ex.Message);
}
}

Expand Down
16 changes: 8 additions & 8 deletions TocSheetExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ public static String getWorksheetCreatedDatePropName()
try
{
if (String.IsNullOrWhiteSpace(prop)) prop = PropertyExtension.getProperty(getTocSheet(), "WorksheetCreatedDatePropName") ?? Settings.Default.WorksheetCreatedDatePropName;
if (String.IsNullOrWhiteSpace(prop) && GlobalFunction.isGermanGUI()) prop = "Datum";
if (String.IsNullOrWhiteSpace(prop) && !GlobalFunction.isGermanGUI()) prop = "Created";
if (String.IsNullOrWhiteSpace(prop)) prop = "Datum";
//if (String.IsNullOrWhiteSpace(prop) && !GlobalFunction.isGermanGUI()) prop = "Created";
}
catch (System.Exception e)
{
Expand All @@ -173,8 +173,8 @@ public static string[] getTocColumns()
{

if (String.IsNullOrWhiteSpace(props)) props = PropertyExtension.getProperty(getTocSheet(), "TocColumns") ?? Settings.Default.TocColumns;
if (String.IsNullOrWhiteSpace(props) && GlobalFunction.isGermanGUI()) props = "Blatt;Datum;Beschreibung;Verantwortlich;ToDo;Status;Info";
if (String.IsNullOrWhiteSpace(props) && !GlobalFunction.isGermanGUI()) props = "Worksheet;Created;Description;Responsible;ToDo;Status;Info";
if (String.IsNullOrWhiteSpace(props)) props = "Blatt;Datum;Beschreibung;Verantwortlich;ToDo;Status;Info";
//if (String.IsNullOrWhiteSpace(props) && !GlobalFunction.isGermanGUI()) props = "Worksheet;Created;Description;Responsible;ToDo;Status;Info";

}
catch (System.Exception e)
Expand Down Expand Up @@ -203,8 +203,8 @@ public static string[] getTocCustomProperties()
{

if (String.IsNullOrWhiteSpace(props)) props = PropertyExtension.getProperty(getTocSheet(), "TocCustomProperties") ?? Settings.Default.TocCustomProperties;
if (String.IsNullOrWhiteSpace(props) && GlobalFunction.isGermanGUI()) props = "Beschreibung;Verantwortlich;ToDo;Status;Info;Datum";
if (String.IsNullOrWhiteSpace(props) && !GlobalFunction.isGermanGUI()) props = "Description;Responsible;ToDo;Status;Info;Created";
if (String.IsNullOrWhiteSpace(props)) props = "Beschreibung;Verantwortlich;ToDo;Status;Info;Datum";
//if (String.IsNullOrWhiteSpace(props) && !GlobalFunction.isGermanGUI()) props = "Description;Responsible;ToDo;Status;Info;Created";

}
catch (System.Exception e)
Expand Down Expand Up @@ -249,8 +249,8 @@ public static String getTocSheetName()
}

if (String.IsNullOrWhiteSpace(sumsheet)) sumsheet = Settings.Default.TocWorksheetName;
if (String.IsNullOrWhiteSpace(sumsheet) && GlobalFunction.isGermanGUI()) sumsheet = "Uebersicht";
if (String.IsNullOrWhiteSpace(sumsheet) && !GlobalFunction.isGermanGUI()) sumsheet = "Toc";
if (String.IsNullOrWhiteSpace(sumsheet)) sumsheet = "Uebersicht";
//if (String.IsNullOrWhiteSpace(sumsheet) && !GlobalFunction.isGermanGUI()) sumsheet = "Toc";

return sumsheet;
}
Expand Down
24 changes: 12 additions & 12 deletions _RibbonBar.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion app.config
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
<applicationSettings>
<ExcelAddIn_TableOfContents.Properties.Settings>
<setting name="UpdateUrl" serializeAs="String">
<value>https://github.com/ahaenggli/ExcelAddIn_TableOfContents/releases/download/latest/ExcelAddIn_TableOfContents.zip</value>
<value>https://github.com/ahaenggli/ExcelAddIn_TableOfContents/releases/latest/download/ExcelAddIn_TableOfContents.zip</value>
</setting>
<setting name="VersionUrl" serializeAs="String">
<value>https://api.github.com/repos/ahaenggli/ExcelAddIn_TableOfContents/releases/latest</value>
</setting>
</ExcelAddIn_TableOfContents.Properties.Settings>
</applicationSettings>
Expand Down

0 comments on commit f35ad26

Please sign in to comment.