Button to Export To CSV

I would like to have a button attached to a tracker view of a dashboard that create as csv file with all of the information in the grid.

Is this possible I am wondering on where to start

thanks for your help.

im on 10.2.300.3

Devin

Right click on the grid export to excel you get it for free :wink:

1 Like

I know lol Im try to help users to get to a csv file for positive pay.

I made a dashboard for this purpose; let the user export to excel then change to a CSV. Unless you like reinventing the wheel… :slight_smile:

search “CSV Button”

The first one that comes up. This thread will walk you through all of the C# to export the csv to a pre-determined location.

1 Like

I dont like when you hard code Column Names Brandon :slight_smile:

1 Like

in that case I had to because I didn’t want everything that was in the grid. There is extra information that can’t get sent with it because the templates/printing is getting it from multiple sources.

If it was just dump whatever is there, I wouldn’t have.

1 Like

I am going to assume you know your .NET, given that you are attempting to do something a bit more advanced.

You might want to .NET Reflect or dotPeek on:

  • Ice.Lib.SharedUtilities.dll
  • Ice.Lib.EpiClientLib.dll

Now these won’t write the CSV for you, but they will help with making sure your CSV is up to the standards. Such as escaping characters, encapsulating spacings or chars with a comma into “” etc…

2018-11-20_1332
c1x

or you could take a chance and just DIY-self: You have to handle the file stream yourself.

foreach (DataRow row in drUD100A)
{
	// Prepare Vars
	string sColumns = String.Empty;
	string sRecords = String.Empty;

	// Prepare Field Formats
	string sColumnFormat = @"'{0}',";
	string sRecordsFormat = @"'{0}',";

	// Determine Field Type and decide if the field gets
	// quotation marks or not.
	// HORIZONTAL LOOP
	foreach (DataColumn colName in row.Table.Columns)
	{
		switch (colName.DataType.Name)
		{
			case "DateTime":
			case "String":
				sRecordsFormat = @"'{0}',";
				break;

			case "Int32":
			case "Decimal":
			case "Boolean":
				sRecordsFormat = @"{0},"; // No paranthesis
				break;

			default:
				sRecordsFormat = @"'{0}',";
				break;
		}

		sColumns += String.Format(sColumnFormat, colName.ToString() );
		sRecords += String.Format(sRecordsFormat, row[ colName ].ToString() );
	}
}

It even has a helper, to give your user a Prompt to select the output location =)


BPM Version: Could be refactored

// Write CSV Headers
Ice.Lib.writeFileLib.FileWriteLine(csvArchiveFullPath, "Company,GroupID,PartNum,RevisionNum,MtlPartNum,MtlSeq,QtyPer,UOMCode,TypeCode,NonStock,MfgComment");
 
bool csvGenerated = false;
bool hasECOMtls = false;
foreach (var ECOMtlRow in ParentECOMtls)
{
    // Create CSV Structure
    string[] csvLine = new string[] {
        ECOMtlRow.Company,
        ECOMtlRow.GroupID,
        ECOMtlRow.PartNum,
        ECOMtlRow.RevisionNum,
        ECOMtlRow.MtlPartNum,
        ECOMtlRow.MtlSeq.ToString(),
        ECOMtlRow.QtyPer.ToString(),
        ECOMtlRow.UOMCode,
        ECOMtlRow.TypeCode,
        ECOMtlRow.NonStock.ToString().ToLower(),
        ECOMtlRow.MfgComment
    };
 
    // Cleanse the Line Just like jcgomez always does
    string x = Ice.Lib.SharedUtilities.ImportExport.CsvWriter.GetCSVLine(csvLine);
 
    log( string.Format("  Writing to CSV: {0}", x) );
    Ice.Lib.writeFileLib.FileWriteLine(csvArchiveFullPath, x);
}

Also in a BPM I like to use Ice.Lib.writeFileLib.FileWriteLine its Async safe and you can write to the same log without getting File Lock issue(s). Like hitting it with 10 DMT’s at the same time, no problemo.

4 Likes

i am looking to do the same here but change my abl to c# but having problems

Output to C:\hardstampdownload\L2.csv .

For each ttLaborDtl where ttLaborDtl.RowMod = 'A' or ttLaborDtl.RowMod = 'U' no-lock:

Find first JobHead where JobHead.Company = ttLaborDtl.Company and JobHead.JobNum = ttLaborDtl.JobNum no-lock no-error .

Find first Part where Part.Company = JobHead.Company and Part.PartNum = JobHead.PartNum no-lock no-error .

export delimiter '¬' JobHead.JobNum JobHead.PartNum ttLaborDtl.EmployeeNum Part.ShortChar01 Part.ShortChar02 Part.ShortChar04 .

End.