コード例 #1
0
        public static void downloadImportData(ICswResources CswResources, CswNbtImportWcf.GenerateSQLReturn Ret, string Filename)
        {
            CswNbtResources CswNbtResources = (CswNbtResources)CswResources;

            CswFilePath FilePathMgr  = new CswFilePath(CswResources);
            string      FullFilePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "\\import\\" + FilePathMgr.getFileNameForSchema(Filename);

            FileStream DataFile = File.OpenRead(FullFilePath);

            DataFile.CopyTo(Ret.stream);
            DataFile.Close();
        }
コード例 #2
0
        public static void downloadImportDefinition(ICswResources CswResources, CswNbtImportWcf.GenerateSQLReturn Ret, string ImportDefName)
        {
            CswNbtResources NbtResources = (CswNbtResources)CswResources;

            Ret.stream = new MemoryStream();
            StreamWriter sw = new StreamWriter(Ret.stream);

            #region document_header
            sw.Write(@"<?xml version=""1.0""?>
<?mso-application progid=""Excel.Sheet""?>
<Workbook
   xmlns=""urn:schemas-microsoft-com:office:spreadsheet""
   xmlns:o=""urn:schemas-microsoft-com:office:office""
   xmlns:x=""urn:schemas-microsoft-com:office:excel""
   xmlns:ss=""urn:schemas-microsoft-com:office:spreadsheet""
   xmlns:html=""http://www.w3.org/TR/REC-html40"">
  <DocumentProperties xmlns=""urn:schemas-microsoft-com:office:office"">
    <Author>Accelrys Inc.</Author>
    <LastAuthor>ChemSW Live</LastAuthor>
    <Created>2007-03-15T23:04:04Z</Created>
    <Company>Accelrys Inc.</Company>
    <Version>1</Version>
  </DocumentProperties>
  <ExcelWorkbook xmlns=""urn:schemas-microsoft-com:office:excel"">
    <WindowHeight>6795</WindowHeight>
    <WindowWidth>8460</WindowWidth>
    <WindowTopX>120</WindowTopX>
    <WindowTopY>15</WindowTopY>
    <ProtectStructure>False</ProtectStructure>
    <ProtectWindows>False</ProtectWindows>
  </ExcelWorkbook>
  <Styles>
    <Style ss:ID=""Default"" ss:Name=""Normal"">
      <Alignment ss:Vertical=""Bottom"" />
      <Borders />
      <Font />
      <Interior />
      <NumberFormat />
      <Protection />
    </Style>
    <Style ss:ID=""s21"">
      <Font x:Family=""Swiss"" ss:Bold=""1"" />
    </Style>
  </Styles>");

            #endregion


            Dictionary <string, DataTable> BindingsTables = _retrieveBindings(NbtResources, ImportDefName);

            DataTable dt = BindingsTables["Order"];

            foreach (KeyValuePair <string, DataTable> Table in BindingsTables)
            {
                //remove the PK column so its not exposed in the excel file
                Table.Value.Columns.Remove("importdef" + Table.Key.TrimEnd(new[] { 's' }) + "id");


                //name each worksheet tab after the table
                sw.Write("<Worksheet ss:Name=\"" + Table.Key + "\"><Table>");

                //add the column headers along the first row of cells
                sw.Write("<Row>");
                foreach (DataColumn Column in Table.Value.Columns)
                {
                    sw.Write("<Cell ss:StyleID=\"s21\"><Data ss:Type=\"String\">" + Column.ColumnName + "</Data></Cell>");
                }
                sw.Write("</Row>");
                sw.Write("<Row />");

                //after an extra blank space, add the data for each row
                foreach (DataRow Row in Table.Value.Rows)
                {
                    sw.Write("<Row>");
                    foreach (DataColumn Column in Table.Value.Columns)
                    {
                        sw.Write("<Cell><Data ss:Type=\"String\">" + Row[Column] + "</Data></Cell>");
                    }
                    sw.Write("</Row>");
                }

                sw.Write("</Table></Worksheet>");
            }

            sw.Write("</Workbook>");
            sw.Flush();
            Ret.stream.Position = 0;
        }