Skip to content

Instantly share code, notes, and snippets.

@smarenich smarenich/ExcelReader.cs
Last active Mar 29, 2016

Embed
What would you like to do?
private static void ImportTransactionsFromFile(PX.SM.FileInfo file)
{
ImportTest graph = new ImportTest();
Byte[] bytes = file.BinData;
using(PX.Data.XLSXReader reader = new XLSXReader(bytes))
{
//Initialising Reader
reader.Reset();
//Creating a dictionary to find column index by name
Dictionary<String, Int32> indexes = reader.IndexKeyPairs.ToDictionary(p => p.Value, p => p.Key);
//Skipping first row with collumns names.
reader.MoveNext();
while(reader.MoveNext())
{
Tran row = graph.Transactions.Insert();
//Transforming External representation to Internal by using SetValueExt method.
graph.Transactions.Cache.SetValueExt(row, "AccountID", reader.GetValue(indexes["Account"]));
graph.Transactions.Cache.SetValueExt(row, "SubID", reader.GetValue(indexes["Account"]));
//Converting to Decimal
row.Qty = Decimal.Parse(reader.GetValue(indexes["Quantity"]));
row.DebitAmt = Decimal.Parse(reader.GetValue(indexes["Debit Amount"]));
row.CreditAmt = Decimal.Parse(reader.GetValue(indexes["Credit Amount"]));
row = graph.Transactions.Update(row);
}
graph.Actions.PressSave();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.