public void GenerateDocument(string path, string keyID, string username) { DocumentCreator dc = new DocumentCreator(); dc.AddString("Date", DateTime.Now.ToShortDateString()); dc.AddString("keyID", keyID); var outputPath = $"{path}//Oswiadczenie.rtf"; dc.CreateDocument(inputPath, outputPath); Process.Start(outputPath); }
public void Button1_Click(object sender, EventArgs e) { try { //Create a Dataset containing the required tables. DataSet MyData = LoadData(); //DocumentCreator represents the API to the NTemplates engine, so we need to instantiate it dc = new DocumentCreator(); //We need to make the DocumentCreator instance aware of the tables by ccalling the AddDataTable method //for each need table. foreach (DataTable dt in MyData.Tables) { dc.AddDataTable(dt); } //We'are handling some events, so we need to define some event handlers dc.BeforeScanRecord += new BeforeScanRecordEventHandler(Dc_BeforeScanRecord); dc.ScanEnded += new ScanEndedEventHandler(Dc_ScanEnded); //By calling the Add<Type> methods of DocumentCreator, we add variables to the //document creator memory space. We can use those for showing values in the report //itself or, we can use them for internal calculations. dc.AddDateTime("invDate", DateTime.Parse(_invoiceDate)); //Invoice date dc.AddDouble(_extprice, 0); //Line total (price * units) dc.AddDouble(_subtotal, 0); //Sum of all extPrices dc.AddDouble(_taxes, 0); //Asume this is a calculated result dc.AddDouble(_total, 0); // subtotal + taxes dc.AddString("title", "Powered by NTemplates"); dc.AddString("address", "http://ntemplates.codeplex.com"); //Finally, we command to create the document using one of the CreateDocument method overloads. //In this case, we are picking a template from a physical file on disc and generating the report //to a physical file too. dc.CreateDocument(_inputPath, _outputPath); if (!_unitTest) { System.Diagnostics.Process.Start(_outputPath); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void AddDataForReport(DocumentCreator dc) { /* Here we are going to add the data that we want to display. Typically it would come * from a Database, a file, or a * web service, but NTemplates doesn´t care about that, it´s up to you and your requirements. * NOTE: NTemplates accepts input data in several formats. * - As ASP.Net data tables. * - As lists of POCOs. * - As variables. * Here we are going to start by using simple variables. * * PLEASE NOTE THAT VARIABLE NAMES ARE CASE SENSITIVE */ dc.AddString("title", "Mr."); dc.AddString("name", "Magoo"); /* We could add a date in it´s native format and then format it as we wish at the template itself. * That´s the recommended way of doing * it because it provides much more flexibility for the end users. * In order to keep things simple we will add the date as string. I will introduce * formatting functions in future * articles. You can explore the examples inclued with the NTemplates downloads. */ dc.AddString("date", _letterDate); dc.AddString("address", "secret for now, and will be revealed at the last moment"); dc.AddString("email", "*****@*****.**"); dc.AddString("inviterName", "Gonzalo Méndez"); dc.AddString("inviterCompany", "Rocksolid Labs"); dc.AddString("inviterUrl", "www.rocksolidlabs.com"); Image ourLogo = Image.FromFile(_logoPath); dc.AddImage("rocksolidlogo", ourLogo); }