Skip to content

Commit

Permalink
Aggiunte nuove funzioni
Browse files Browse the repository at this point in the history
  • Loading branch information
Clouz committed May 13, 2017
1 parent fb1a5b3 commit cab2a1d
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ExcelGenericUDF/ExcelGenericUDF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
<Private>True</Private>
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
<EmbedInteropTypes>True</EmbedInteropTypes>
<HintPath>..\packages\Microsoft.Office.Interop.Excel.15.0.4795.1000\lib\net20\Microsoft.Office.Interop.Excel.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down
89 changes: 88 additions & 1 deletion ExcelGenericUDF/Udf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using ExcelDna.Integration;
using ExcelDna.IntelliSense;

using Excel = Microsoft.Office.Interop.Excel;

namespace ExcelGenericUDF
{
public class Udf : IExcelAddIn
Expand All @@ -21,7 +23,7 @@ public void AutoClose()

}

[ExcelFunction(Description = "Data una matrice con tipico, potenza e lunghezza del cavo restituisce la sezione")]
[ExcelFunction(Description = "Data una matrice con tipico, potenza e lunghezza del cavo restituisce la sezione", Name ="Claudio.CalcolaCavi")]
public static string ClaudioCalcolaCavi(
[ExcelArgument(Description = "Inserire una matrice dove nella prima colonna è indicato il tipico, nella seconda la potenza (kW) e nelle restanti righe di intestazione le varie lunghezze del cavo", Name = "Matrice Cavi")] object[,] matriceCavi,
[ExcelArgument(Description = "Inserire il tipico desiderato già presente nella matrice", Name = "Tipico")] string tipico,
Expand Down Expand Up @@ -60,5 +62,90 @@ public static string ClaudioCalcolaCavi(
return e.ToString();
}
}

[ExcelFunction(Description = "Dato il numero della scheda ne restituisce il nome",Name = "Claudio.Scheda.Nome")]
public static object ClaudioNomeScheda(
[ExcelArgument(Name = "Numero Scheda", Description = "Inserire il numero della scheda")] int i)
{
try
{
Excel.Application application = (Excel.Application)ExcelDnaUtil.Application;
Excel.Workbook workbook = application.ActiveWorkbook;
Excel.Worksheet worksheets = workbook.Worksheets[i];

return worksheets.Name;
}
catch (Exception e)
{
return e.ToString();
}
}

[ExcelFunction(Description = "Dato il numero della scheda ne modifica il nome", Name ="Claudio.Scheda.Rinomia")]
public static object ClaudioRinomicaScheda(
[ExcelArgument(Name ="Numero Scheda", Description ="Inserire il numero della scheda")] int i,
[ExcelArgument(Name ="Nome", Description ="Inserire il nuovo nome della scheda")] string nome)
{
try
{
Excel.Application application = (Excel.Application)ExcelDnaUtil.Application;
Excel.Workbook workbook = application.ActiveWorkbook;
Excel.Worksheet worksheets = workbook.Worksheets[i];

worksheets.Name = nome;

return worksheets.Name;
}
catch (Exception e)
{
return e.ToString();
}
}
[ExcelFunction(Name ="Claudio.Stringa.Spazia", Description ="Data una stringa ed un pattern ne spazia il contenuto")]
public static string ClaudioSepara(
[ExcelArgument(Name ="Stringa Iniziale", Description ="")] string nome,
[ExcelArgument(Name = "Pattern", Description = "Indica con quanti caratteri separatori riempiere la sottostringa. es. 10-10-5")] string Pattern,
[ExcelArgument(Name = "Carattere Separatore", Description = "Indica con quale carattere la stringa viene separata")] string Separatore,
[ExcelArgument(Name = "Carattere di Riempimento", Description = "Indica con quale carattere riempire la stringa")] string CarattereRiempimento)
{
try
{
string[] PatternDiviso = Pattern.Split(char.Parse(Separatore));
var lista = nome.Split(char.Parse(Separatore));

string nuovaStringa = "";

for (int i = 0; i < lista.Length; i++)
{
int quantitaSpazi;
try
{
if (int.Parse(PatternDiviso[i]) == 0)
{
quantitaSpazi = 0;
}
else
{
quantitaSpazi = int.Parse(PatternDiviso[i]) - lista[i].Length;
}
}
catch (Exception)
{
quantitaSpazi = 0;
}

nuovaStringa = nuovaStringa + new string(char.Parse(CarattereRiempimento), quantitaSpazi) + lista[i] + Separatore;
}
nuovaStringa = nuovaStringa.Substring(0, nuovaStringa.Length - 1);

return nuovaStringa;
}
catch (Exception e)
{
return $"Stringa non corrispondente al pattern: {e.ToString()}";
}

}

}
}
1 change: 1 addition & 0 deletions ExcelGenericUDF/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<package id="ExcelDna.AddIn" version="0.33.9" targetFramework="net452" />
<package id="ExcelDna.Integration" version="0.33.9" targetFramework="net452" />
<package id="ExcelDna.IntelliSense" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.Office.Interop.Excel" version="15.0.4795.1000" targetFramework="net452" />
<package id="UIAComWrapper" version="1.1.0.14" targetFramework="net452" />
</packages>

0 comments on commit cab2a1d

Please sign in to comment.