//
// This code is part of Document Solutions for Word demos.
// Copyright (c) MESCIUS inc. All rights reserved.
//
using System;
using System.IO;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
using System.Xml;
using GrapeCity.Documents.Word;
namespace DsWordWeb.Demos
{
// This example shows how text input data that is stored in different data
// sources that are formatted for different cultures (in this example,
// floating point values are stored with points and commas as decimal
// separators) can be correctly processed by DsWord's report templates
// if the correct culture is specified for each data source.
public class DataTplCultureIn
{
public GcWordDocument CreateDocx()
{
// Strings with floating-point data using point as the decimal separator:
var dsUs = new string[] { "1.234", "56.78", "987.65", "3.14" };
// Same data using comma as the decimal separator:
var dsFr = new string[] { "1,234", "56,78", "987,65", "3,14" };
var doc = new GcWordDocument();
doc.Body.Paragraphs.Add(
"The two columns of data below come from two different data sources, " +
"with different cultures specified for each data source. " +
"Numbers in the left column were converted from strings with point as the decimal separator, " +
"with \"en-US\" culture specified for the data source. " +
"Numbers in the right column were converted from strings with comma as the decimal separator, " +
"with \"fr-FR\" culture specified for the data source. " +
"Both sets of data were converted correctly using the \"todouble()\" formatter.");
doc.Body.Paragraphs.Add("{{#dsUs}:seq(x)}{{#dsFr}:follow(x)}{{dsUs.value}:todouble()} == {{dsFr.value}:todouble()}{{/dsFr}}{{/dsUs}}");
doc.DataTemplate.DataSources.Add("dsUs", dsUs, CultureInfo.GetCultureInfo("en-US"));
doc.DataTemplate.DataSources.Add("dsFr", dsFr, CultureInfo.GetCultureInfo("fr-FR"));
// Generate the document by template processing
doc.DataTemplate.Process(CultureInfo.GetCultureInfo("en-US"));
// Done:
return doc;
}
}
}