Custom Data Merging

In this demo, a spreadsheet template is loaded into the Bootstrap Spreadsheet and programmatically populated with data taken from an XML file. The template displays the predefined report layout and contains specific aggregate formulas. The data is retrieved from an XML file and merged with the corresponding worksheet cells into an integrated report. As a result, a worksheet represents a complete report calculated automatically.

<dx:BootstrapSpreadsheet ID="SpreadsheetCustomDataMerging" runat="server" ActiveTabIndex="0" ShowConfirmOnLosingChanges="false"
    OnLoad="SpreadsheetCustomDataMerging_Load">
</dx:BootstrapSpreadsheet>
int StartRowIndex = 10,
    MaxReportRowsCount = 15;
protected Worksheet Worksheet { get { return SpreadsheetCustomDataMerging.Document.Worksheets.ActiveWorksheet; } }
protected void SpreadsheetCustomDataMerging_Load(object sender, EventArgs e) {
    if(!Page.IsPostBack) {
        SpreadsheetCustomDataMerging.Open(Path.Combine(DirectoryManagmentUtils.CurrentDataDirectory, @"Spreadsheet\\ExpenseReport.xlsx"));
        var expenses = LoadExpensesReportData();
        FillGeneralReportInfo(expenses.Info);
        FillReport(expenses.Expenses);
        SpreadsheetCustomDataMerging.Document.Worksheets.ActiveWorksheet.ActiveView.ShowGridlines = false;
        SpreadsheetCustomDataMerging.Document.History.Clear();
    }
}
ExpensesReport LoadExpensesReportData() {
    using(Stream stream = File.OpenRead(HttpContext.Current.Server.MapPath("~/App_Data/Expenses.xml"))) {
        var serializer = new System.Xml.Serialization.XmlSerializer(typeof(ExpensesReport));
        return (ExpensesReport)serializer.Deserialize(stream);
    }
}
void FillGeneralReportInfo(ExpensesInfo info) {
    Worksheet["D2"].Value = info.Purpose;
    Worksheet["D3"].Value = info.StatementNumber;
    Worksheet["C7"].Value = info.EmployeeName;
    Worksheet["C8"].Value = info.EmployeeDepartment;
    Worksheet["G7"].Value = info.EmployeePosition;
    Worksheet["G8"].Value = info.Manager;
    Worksheet["K7"].Value = info.SSN;
    Worksheet["K8"].Value = info.EmployeeID;
}
void FillReport(List<Expense> report) {
    int reportCount = Math.Min(report.Count, MaxReportRowsCount);
    for(int i = 0; i < reportCount; i++) {
        Expense expense = report[i];
        int rowOffset = StartRowIndex + i + 1;
        Worksheet["B" + rowOffset].Value = expense.CreationDate;
        Worksheet["C" + rowOffset].Value = expense.Account;
        Worksheet["D" + rowOffset].Value = expense.Description;
        Worksheet["F" + rowOffset].Value = expense.Hotel;
        Worksheet["H" + rowOffset].Value = expense.Transport;
        Worksheet["I" + rowOffset].Value = expense.Fuel;
        Worksheet["J" + rowOffset].Value = expense.Meals;
        Worksheet["L" + rowOffset].Value = expense.Phone;
        Worksheet["M" + rowOffset].Value = expense.Entertainment;
        Worksheet["N" + rowOffset].Value = expense.Misc;
    }
}
[XmlRoot("Expenses")]
public class ExpensesReport {
    public ExpensesReport() {
        Info = new ExpensesInfo();
        Expenses = new List<Expense>();
    }
    [XmlElement]
    public ExpensesInfo Info { get; set; }
    [XmlElement("Expense")]
    public List<Expense> Expenses { get; set; }
}
public class ExpensesInfo {
    [XmlAttribute]
    public string Purpose { get; set; }
    [XmlAttribute]
    public int StatementNumber { get; set; }
    [XmlAttribute]
    public int EmployeeID { get; set; }
    [XmlAttribute]
    public string EmployeeName { get; set; }
    [XmlAttribute]
    public string EmployeePosition { get; set; }
    [XmlAttribute]
    public string SSN { get; set; }
    [XmlAttribute]
    public string EmployeeDepartment { get; set; }
    [XmlAttribute]
    public string Manager { get; set; }
}
public class Expense {
    [XmlAttribute(AttributeName = "Date")]
    public DateTime CreationDate { get; set; }
    [XmlAttribute]
    public int Account { get; set; }
    [XmlAttribute]
    public string Description { get; set; }
    [XmlAttribute]
    public double Hotel { get; set; }
    [XmlAttribute]
    public double Transport { get; set; }
    [XmlAttribute]
    public double Fuel { get; set; }
    [XmlAttribute]
    public double Meals { get; set; }
    [XmlAttribute]
    public double Phone { get; set; }
    [XmlAttribute]
    public double Misc { get; set; }
    [XmlAttribute]
    public double Entertainment { get; set; }
}
Screen Size
Color Themes
Demo QR Code