PIPSSOU
New member
- Joined
- Nov 2, 2023
- Messages
- 1
- Programming Experience
- Beginner
Good morning !
I'm a beginner in Csharp.
I would like to write data from a datatable to a Csv file.
My problem is that I also want to transform certain data which is originally in columns into row headers.
My Code
I'm a beginner in Csharp.
I would like to write data from a datatable to a Csv file.
My problem is that I also want to transform certain data which is originally in columns into row headers.
Code:
Exemple:
Nom Prenoms Rubrique Paie Montant
DOE John Salairebase 1000000
DOE John Transport 20000
Expected result
Nom Prenoms salairebase Transport
DOE John 1000000 20000
Obtained result
Nom Prenoms salairebase Transport
DOE John 20000 1000000
C#:
if (str3 == "RUBRIQUES PAIE") {
// Ecriture des entetes Agent
for (int index = 0; index < count2; ++index) {
streamWriter.Write(data.Columns[index].Caption + ";");
}
// Ecriture des entetes Rubriques
for (int index = 0; index < rubCount; ++index) {
if (index == rubCount - 1)
streamWriter.WriteLine(stringList[index]);
else
streamWriter.Write(stringList[index] + ";");
}
int indexRub = count2 - 1;
string lastAgent = "000";
int controle = 0;
// Parcours des Agents par Matricule
foreach(DataRow row in (InternalDataCollectionBase) data.Rows) {
string headAgent = "";
for (int index = 0; index < count2; ++index) {
string str0 = data.Columns[index].DataType.Name == "DateTime" ? row[index].ToString().Substring(0, 10) : row[index].ToString();
headAgent += str0 + ";";
}
// Infos Agent
if (headAgent != lastAgent) {
if (lastAgent != "000") {
streamWriter.WriteLine("");
controle = 0;
}
streamWriter.Write(headAgent);
}
lastAgent = headAgent;
controle++;
// Infos Rubriques
streamWriter.Write(row[indexMt].ToString() + (indexRub == controle ? "" : ","));
}
streamWriter.Flush();
streamWriter.Dispose();
Last edited by a moderator: