DataTplCultureIn.cs
  1. //
  2. // This code is part of Document Solutions for Word demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Globalization;
  11. using System.Xml;
  12. using GrapeCity.Documents.Word;
  13.  
  14. namespace DsWordWeb.Demos
  15. {
  16. // This example shows how text input data that is stored in different data
  17. // sources that are formatted for different cultures (in this example,
  18. // floating point values are stored with points and commas as decimal
  19. // separators) can be correctly processed by DsWord's report templates
  20. // if the correct culture is specified for each data source.
  21. public class DataTplCultureIn
  22. {
  23. public GcWordDocument CreateDocx()
  24. {
  25. // Strings with floating-point data using point as the decimal separator:
  26. var dsUs = new string[] { "1.234", "56.78", "987.65", "3.14" };
  27. // Same data using comma as the decimal separator:
  28. var dsFr = new string[] { "1,234", "56,78", "987,65", "3,14" };
  29.  
  30. var doc = new GcWordDocument();
  31. doc.Body.Paragraphs.Add(
  32. "The two columns of data below come from two different data sources, " +
  33. "with different cultures specified for each data source. " +
  34. "Numbers in the left column were converted from strings with point as the decimal separator, " +
  35. "with \"en-US\" culture specified for the data source. " +
  36. "Numbers in the right column were converted from strings with comma as the decimal separator, " +
  37. "with \"fr-FR\" culture specified for the data source. " +
  38. "Both sets of data were converted correctly using the \"todouble()\" formatter.");
  39. doc.Body.Paragraphs.Add("{{#dsUs}:seq(x)}{{#dsFr}:follow(x)}{{dsUs.value}:todouble()} == {{dsFr.value}:todouble()}{{/dsFr}}{{/dsUs}}");
  40. doc.DataTemplate.DataSources.Add("dsUs", dsUs, CultureInfo.GetCultureInfo("en-US"));
  41. doc.DataTemplate.DataSources.Add("dsFr", dsFr, CultureInfo.GetCultureInfo("fr-FR"));
  42.  
  43. // Generate the document by template processing
  44. doc.DataTemplate.Process(CultureInfo.GetCultureInfo("en-US"));
  45.  
  46. // Done:
  47. return doc;
  48. }
  49. }
  50. }
  51.