Initialize
Liest aus einer Excel Datei eine Spalte aus
This commit is contained in:
commit
50a8e56720
Binary file not shown.
BIN
.vs/Test_ExcelReadOneColumn.git/v17/.suo
Normal file
BIN
.vs/Test_ExcelReadOneColumn.git/v17/.suo
Normal file
Binary file not shown.
BIN
Daten/Test.xlsx
Normal file
BIN
Daten/Test.xlsx
Normal file
Binary file not shown.
25
Test_ExcelReadOneColumn.git.sln
Normal file
25
Test_ExcelReadOneColumn.git.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.8.34511.84
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_ExcelReadOneColumn", "Test_ExcelReadOneColumn\Test_ExcelReadOneColumn.csproj", "{A533264B-2481-4085-8A30-327A3D33A778}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{A533264B-2481-4085-8A30-327A3D33A778}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A533264B-2481-4085-8A30-327A3D33A778}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A533264B-2481-4085-8A30-327A3D33A778}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A533264B-2481-4085-8A30-327A3D33A778}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {F32C184E-C7E0-4ABE-A8A5-D8CA1A41B8AD}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
6
Test_ExcelReadOneColumn/App.config
Normal file
6
Test_ExcelReadOneColumn/App.config
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||
</startup>
|
||||
</configuration>
|
||||
224
Test_ExcelReadOneColumn/Program.cs
Normal file
224
Test_ExcelReadOneColumn/Program.cs
Normal file
@ -0,0 +1,224 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.Office.Interop.Excel; // zusätzlich ist der Projektverweis auf COM -> Microsoft Excel xx-Objectlibrary
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Test_ExcelReadOneColumn
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
#region Version und Copyright
|
||||
// Version und Copyright
|
||||
static string programName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen
|
||||
static string programVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
static object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
|
||||
static string copyright = GenerateCopyright();
|
||||
|
||||
//Assembly Datum und Zeit
|
||||
static DateTime value = AssemblyDateTime();
|
||||
string date = value.ToShortDateString();
|
||||
string time = value.ToLongTimeString();
|
||||
|
||||
private static DateTime AssemblyDateTime()
|
||||
{
|
||||
var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
|
||||
var buildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * version.Build + TimeSpan.TicksPerSecond * 2 * version.Revision));
|
||||
//Tage seit dem 1. Januar 2000 und Sekunden seit Mitternacht, (multiplizier mit 2 ergibt das Original)
|
||||
return buildDateTime;
|
||||
}
|
||||
|
||||
private static string CurrentYear()
|
||||
{
|
||||
DateTime dtn = DateTime.Now;
|
||||
return dtn.Year.ToString();
|
||||
}
|
||||
|
||||
private static string StartYear()
|
||||
{
|
||||
string startYear = "";
|
||||
if (((AssemblyCopyrightAttribute)attributes[0]).Copyright.Contains("Copyright © "))
|
||||
{
|
||||
startYear = ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace("Copyright © ", "");
|
||||
while (startYear.StartsWith(" "))
|
||||
{
|
||||
startYear = startYear.Remove(0, 1);
|
||||
}
|
||||
|
||||
if (startYear.Contains("-"))
|
||||
{
|
||||
startYear = startYear.Remove(startYear.IndexOf("-"));
|
||||
}
|
||||
else
|
||||
{
|
||||
startYear = startYear.Remove(startYear.IndexOf(" "));
|
||||
}
|
||||
return startYear;
|
||||
}
|
||||
else
|
||||
{
|
||||
DateTime dtn = DateTime.Now;
|
||||
return dtn.Year.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private static string GenerateCopyright()
|
||||
{
|
||||
string startYear = StartYear();
|
||||
string currentYear = CurrentYear();
|
||||
|
||||
if (startYear == currentYear)
|
||||
{
|
||||
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
|
||||
}
|
||||
else
|
||||
{
|
||||
string temp = ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
|
||||
string start = temp.Remove(temp.IndexOf(startYear) - 1);
|
||||
string end = (temp.Remove(0, temp.IndexOf(" by")));
|
||||
|
||||
return String.Concat(start, " ", startYear, "-", currentYear, end);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Programm-Info
|
||||
/// <summary>
|
||||
/// Contains the name of the program file
|
||||
/// </summary>
|
||||
public static string ProgramName { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// Contains the version of the program file
|
||||
/// </summary>
|
||||
public static string ProgramVersion { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// Contains the copyright notice
|
||||
/// </summary>
|
||||
public static string Copyright { set; get; }
|
||||
|
||||
private static void SetProgramInfo()
|
||||
{
|
||||
//Name, Version und Copyright setzen
|
||||
ProgramName = programName;
|
||||
ProgramVersion = programVersion;
|
||||
Copyright = copyright;
|
||||
}
|
||||
#endregion
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// Programminformationen setzen
|
||||
SetProgramInfo();
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TODO: Hier Programmcode einfügen
|
||||
string fileName = @"C:\CAD\Git-WorkRepository\VisualStudio\_TEST\Test_ExcelReadOneColumn.git\Daten\Test.xlsx";
|
||||
List<string> machines = new List<string>();
|
||||
|
||||
var ld = new Program();
|
||||
machines = ld.LoadData(fileName); //Alle Maschinentypen suchen
|
||||
machines = ld.EliminateDuplicates(machines);
|
||||
machines = ld.SortData(machines);
|
||||
|
||||
string output = "";
|
||||
foreach (var item in machines)
|
||||
{
|
||||
output += item + "\r\n";
|
||||
}
|
||||
Console.WriteLine(output);
|
||||
Console.ReadLine();
|
||||
//TODO: machines filtern
|
||||
|
||||
//
|
||||
////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
private List<string> LoadData(string fileName)
|
||||
{
|
||||
List<string> data = new List<string>();
|
||||
|
||||
Microsoft.Office.Interop.Excel.Application ExcelApplication;
|
||||
Microsoft.Office.Interop.Excel.Workbook ExcelWorkbook;
|
||||
Microsoft.Office.Interop.Excel.Worksheet ExcelWorkSheet;
|
||||
ExcelApplication = null;
|
||||
|
||||
ExcelApplication = new Microsoft.Office.Interop.Excel.Application();
|
||||
ExcelWorkbook = ExcelApplication.Workbooks.Open(fileName);
|
||||
ExcelWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)ExcelWorkbook.ActiveSheet;
|
||||
|
||||
int numberOfUsedRows = ExcelWorkSheet.UsedRange.Rows.Count;
|
||||
|
||||
for (int i = 5; i < numberOfUsedRows + 1; i++)
|
||||
{
|
||||
if (ExcelWorkSheet.Cells[i, "A"].Value2 != null)
|
||||
{
|
||||
data.Add(ExcelWorkSheet.Cells[i, "A"].Value2.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
//Excel beenden
|
||||
if (ExcelApplication != null)
|
||||
{
|
||||
ExcelApplication.Quit();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private List<string> EliminateDuplicates(List<string> machines)
|
||||
{
|
||||
List<string> data = new List<string>();
|
||||
|
||||
for (int i = 0; i < machines.Count; i++)
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
//Wenn es schon Daten gibt, dann vergleichen
|
||||
bool exist = false;
|
||||
|
||||
for (int j = 0; j < data.Count; j++)
|
||||
{
|
||||
if (machines[i] == data[j])
|
||||
{
|
||||
exist = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!exist)
|
||||
{
|
||||
data.Add(machines[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
exist = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
data.Add(machines[i]); //Wenn es noch keine Daten gibt, dann aufnehmen
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private List<string> SortData(List<string> machines)
|
||||
{
|
||||
List<string> data = new List<string>();
|
||||
|
||||
if (machines != null)
|
||||
{
|
||||
data = machines;
|
||||
data.Sort();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Test_ExcelReadOneColumn/Properties/AssemblyInfo.cs
Normal file
36
Test_ExcelReadOneColumn/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die einer Assembly zugeordnet sind.
|
||||
[assembly: AssemblyTitle("Test_ExcelReadOneColumn")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Test_ExcelReadOneColumn")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2022 by Eugen Höglinger")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
|
||||
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
|
||||
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
||||
[assembly: Guid("a533264b-2481-4085-8a30-327a3d33a778")]
|
||||
|
||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
//
|
||||
// Hauptversion
|
||||
// Nebenversion
|
||||
// Buildnummer
|
||||
// Revision
|
||||
//
|
||||
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
||||
// indem Sie "*" wie unten gezeigt eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
56
Test_ExcelReadOneColumn/Test_ExcelReadOneColumn.csproj
Normal file
56
Test_ExcelReadOneColumn/Test_ExcelReadOneColumn.csproj
Normal file
@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{A533264B-2481-4085-8A30-327A3D33A778}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>Test_ExcelReadOneColumn</RootNamespace>
|
||||
<AssemblyName>Test_ExcelReadOneColumn</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
|
||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
BIN
Test_ExcelReadOneColumn/bin/Debug/Test_ExcelReadOneColumn.exe
Normal file
BIN
Test_ExcelReadOneColumn/bin/Debug/Test_ExcelReadOneColumn.exe
Normal file
Binary file not shown.
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||
</startup>
|
||||
</configuration>
|
||||
BIN
Test_ExcelReadOneColumn/bin/Debug/Test_ExcelReadOneColumn.pdb
Normal file
BIN
Test_ExcelReadOneColumn/bin/Debug/Test_ExcelReadOneColumn.pdb
Normal file
Binary file not shown.
@ -0,0 +1,4 @@
|
||||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
|
||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
||||
40a3bebb216fa6e1c34108a62e246a430f525cb0750367f8395e63f9efbc1e9b
|
||||
@ -0,0 +1,7 @@
|
||||
C:\CAD\Git-WorkRepository\VisualStudio\_TEST\Test_ExcelReadOneColumn.git\Test_ExcelReadOneColumn\bin\Debug\Test_ExcelReadOneColumn.exe.config
|
||||
C:\CAD\Git-WorkRepository\VisualStudio\_TEST\Test_ExcelReadOneColumn.git\Test_ExcelReadOneColumn\bin\Debug\Test_ExcelReadOneColumn.exe
|
||||
C:\CAD\Git-WorkRepository\VisualStudio\_TEST\Test_ExcelReadOneColumn.git\Test_ExcelReadOneColumn\bin\Debug\Test_ExcelReadOneColumn.pdb
|
||||
C:\CAD\Git-WorkRepository\VisualStudio\_TEST\Test_ExcelReadOneColumn.git\Test_ExcelReadOneColumn\obj\Debug\Test_ExcelReadOneColumn.csproj.AssemblyReference.cache
|
||||
C:\CAD\Git-WorkRepository\VisualStudio\_TEST\Test_ExcelReadOneColumn.git\Test_ExcelReadOneColumn\obj\Debug\Test_ExcelReadOneColumn.csproj.CoreCompileInputs.cache
|
||||
C:\CAD\Git-WorkRepository\VisualStudio\_TEST\Test_ExcelReadOneColumn.git\Test_ExcelReadOneColumn\obj\Debug\Test_ExcelReadOneColumn.exe
|
||||
C:\CAD\Git-WorkRepository\VisualStudio\_TEST\Test_ExcelReadOneColumn.git\Test_ExcelReadOneColumn\obj\Debug\Test_ExcelReadOneColumn.pdb
|
||||
BIN
Test_ExcelReadOneColumn/obj/Debug/Test_ExcelReadOneColumn.exe
Normal file
BIN
Test_ExcelReadOneColumn/obj/Debug/Test_ExcelReadOneColumn.exe
Normal file
Binary file not shown.
BIN
Test_ExcelReadOneColumn/obj/Debug/Test_ExcelReadOneColumn.pdb
Normal file
BIN
Test_ExcelReadOneColumn/obj/Debug/Test_ExcelReadOneColumn.pdb
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user