Das Lesen von Excel -Blatt in meinem .NET 8 -Code funktioniert nicht, ich erhalte Nummern anstelle des tatsächlichen TexC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Das Lesen von Excel -Blatt in meinem .NET 8 -Code funktioniert nicht, ich erhalte Nummern anstelle des tatsächlichen Tex

Post by Anonymous »

Ich habe eine .NET 8 -Anwendung, in der ein Excel -Blatt .xlsx in SharePoint online gespeichert ist. src = "https://i.sstatic.net/vsf3o2o7.png"/>
Text:

Code: Select all

58955   | Bing Organic |    Organic |   n/a | | Bing - Organic  |   | 28674 |   n/a  | SERPs    |   |   | 01/10/2024    | 01/10/2024    | 31/10/2024
< /code>
Dies ist der Code, um diese Datei zu lesen: < /p>
var stream = await httpClient.GetStreamAsync(uri);
using var doc = SpreadsheetDocument.Open(stream, false);
var workbookPart = doc.WorkbookPart;

var sheet = workbookPart.Workbook.Sheets.Elements().First();
var worksheetPart = (WorksheetPart)workbookPart.GetPartById(sheet.Id!);

var filteredResults = new List();

using var reader = OpenXmlReader.Create(worksheetPart);
bool isFirstRow = true;

while (reader.Read())
{
if (reader.ElementType != typeof(Row))
continue;

var row = (Row)reader.LoadCurrentElement();
var cells = row.Elements().ToList();

if (isFirstRow)
{
isFirstRow = false; // skip header
continue;
}

// Extract cell values (adjust index based on actual structure)
string GetCellValue(int index)
{
if (index >= cells.Count)
return "";

var cell = cells[index];
var value = cell.InnerText;

return value;
}

string vnumber = GetCellValue(7);

if (vnumber != null && leads.Where(a => a.MSID == vnumber).Count() > 0)
{
_logger.LogInformation("vnumber" + vnumber);
var update = leads.FirstOrDefault(a => a.MSID == vnumber);
update.UMSID = GetCellValue(0);
_logger.LogInformation(GetCellValue(0));
update.Publisher = GetCellValue(1);
_logger.LogInformation(GetCellValue(1));
update.Medium = GetCellValue(2);
_logger.LogInformation(GetCellValue(2));
update.Vendor = GetCellValue(3);
_logger.LogInformation(GetCellValue(3));
update.UTM_campaign = GetCellValue(4);
_logger.LogInformation(GetCellValue(4));
update.nterneer_Source = GetCellValue(5);
_logger.LogInformation(GetCellValue(5));
update.UTM_Source = GetCellValue(6);
update.Focus = GetCellValue(8);
update.Creative = GetCellValue(9);
update.Test_Type = GetCellValue(10);
update.Test_Creative = GetCellValue(11);
_logger.LogInformation(GetCellValue(12));
update.Start_week_month = !string.IsNullOrWhiteSpace(GetCellValue(12))? DateTime.FromOADate(double.Parse(GetCellValue(12))):null;
_logger.LogInformation(GetCellValue(13));

update.Start_date = !string.IsNullOrWhiteSpace(GetCellValue(13)) ? DateTime.FromOADate(double.Parse(GetCellValue(13))) : null;
_logger.LogInformation(GetCellValue(14));
update.End_date = !string.IsNullOrWhiteSpace(GetCellValue(14)) ? DateTime.FromOADate(double.Parse(GetCellValue(14))) : null;
update.Impressions = GetCellValue(15);
update.CPM_CPL = GetCellValue(16);
update.Cost = GetCellValue(17);
update.Invoice_Status = GetCellValue(18);
update.Open = GetCellValue(19);
update.Open_rate = GetCellValue(20);
update.Clicks_publisher_visits_GA_ = GetCellValue(21);

update.CTR = GetCellValue(22);
update.Notes = GetCellValue(23);
update.Count_of_Leads = GetCellValue(24);
update.Brand_Ambassador = GetCellValue(25);
}
}
< /code>
Hier ist die Ausgabe, die ich für die oben gezeigte Zeile erhalten habe: < /p>
2025-04-30T16:06:41Z   [Information]   vnumber28674
2025-04-30T16:06:41Z   [Information]   58955
2025-04-30T16:06:41Z   [Information]   51
2025-04-30T16:06:41Z   [Information]   48
2025-04-30T16:06:41Z   [Information]   35
2025-04-30T16:06:41Z   [Information]   35
2025-04-30T16:06:41Z   [Information]   45566
2025-04-30T16:06:41Z   [Information]   2024
2025-04-30T16:06:41Z   [Information]   10
< /code>
Warum habe ich die eigentliche Zeichenfolge nicht bekommen? Und warum bekomme ich immer Zahlen? Warum wird das Datum als 45566 
zurückgegeben. Welches ist der Doppelwert der Datumszeit, während er manchmal nur das Jahr und dann nur den Monat zurückgibt?
Danke

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post