Initila commit

This commit is contained in:
dev-mkoebis
2026-04-23 14:26:26 +02:00
parent 7d4d43fb5a
commit cccbb667a8
14 changed files with 1293 additions and 0 deletions

85
Business/ExcelReader.cs Normal file
View File

@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;
namespace MergeCMInpro.Business
{
internal class ExcelReader
{
public static string ReadExcel(string filename, string vorgangId)
{
Excel.Application excel = null;
excel = new Excel.Application();
excel.Visible = true;
Excel.Workbook wkb = null;
wkb = Open(excel, filename);
Excel.Range searchedRange = excel.get_Range("A1", "XFD1048576");
Excel.Range currentFind = searchedRange.Find(vorgangId);
Excel.Sheets excelSheets = wkb.Worksheets;
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(1);
string res = string.Empty;
if (currentFind != null)
{
var cellValue = Convert.ToString((excelWorksheet.Cells[currentFind.Row, currentFind.Column+10] as Excel.Range).Value);
DateTime dt = DateTime.Parse(cellValue);
res = dt.ToShortDateString();
}
else
{
res = "01.01.1900";
//TODO: Logger, falls nicht gefunden. Und sonst wird 01.01.1900 als default gesetzt
}
wkb.Close(true);
excel.Quit();
return res;
}
public static Excel.Workbook Open(Excel.Application excelInstance,
string fileName, bool readOnly = false, bool editable = true,
bool updateLinks = true)
{
Excel.Workbook book = excelInstance.Workbooks.Open(
fileName, updateLinks, readOnly,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, editable, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
return book;
}
public static void ReleaseComObjects(ref List<object> comObjects)
{
for (int i = 0; i < comObjects.Count; i++)
{
object obj = comObjects[i];
if (Marshal.IsComObject(obj))
{
while (obj != null && Marshal.ReleaseComObject(obj) != 0) ;
while (obj != null && Marshal.FinalReleaseComObject(obj) != 0) ;
}
obj = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
}
public static int GetColumnNumber(string column)//A --> 1 B --> 2 CI --> 87
{
int col = 0;
char[] temp = column.ToUpper().ToCharArray();
for (int i = temp.Length - 1; i >= 0; i--)
{
int num = Convert.ToInt32(temp[i]) - 64;
col += num * Convert.ToInt32(Math.Pow(26, temp.Length - 1 - i));
}
return col;
}
}
}