当前位置: 首页>>代码示例>>C#>>正文


C# IDataTable.GetColumnType方法代码示例

本文整理汇总了C#中IDataTable.GetColumnType方法的典型用法代码示例。如果您正苦于以下问题:C# IDataTable.GetColumnType方法的具体用法?C# IDataTable.GetColumnType怎么用?C# IDataTable.GetColumnType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDataTable的用法示例。


在下文中一共展示了IDataTable.GetColumnType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExportToExcel

        public static void ExportToExcel(IDataTable<DataRow> data, string filename,Protocol.Structure.WaitObject wt)
        {
            if (data == null)
                return;
            var excel = new ApplicationClass();
            if (excel == null)
                throw new Exception("Excel无法启动");
            int rowNum = data.RowCount;
            string[] columns = data.GetColumnsList();
            int columnNum = columns.Length;
            wt.Flags = new int[1];
            wt.Max = rowNum * columnNum;
            int rowIndex = 1;
            int columnIndex = 0;
            var book = excel.Application.Workbooks.Add(true);
            try
            {
                foreach (var column in columns)
                {
                    columnIndex++;
                    excel.Cells[rowIndex, columnIndex] = column;
                    if (data.GetColumnType(column) == typeof(string))
                        excel.get_Range(excel.Cells[rowIndex + 1, columnIndex], excel.Cells[rowNum + 1, columnIndex]).NumberFormatLocal = "@";
                }
                for (int i = 0; i < rowNum; i++)
                {
                    rowIndex++;
                    columnIndex = 0;
                    for (int j = 0; j < columnNum; j++)
                    {
                        columnIndex++;
                        excel.Cells[rowIndex, columnIndex] = data[i,columns[j]];
                        wt.Flags[0]++;
                    }

                }
                excel.DisplayAlerts = false;
                excel.AlertBeforeOverwriting = false;
                book.SaveCopyAs(filename);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                book.Close(false);
                book = null;
                excel.Quit();
                excel = null;
            }
        }
开发者ID:noelhx,项目名称:MultiParamProcessOptimization,代码行数:52,代码来源:BasicExcelOperation.cs

示例2: Rpart

 public static Tuple<Image, string, double[, ]> Rpart(IDataTable<DataRow> data,int width,int height, string targetcolumn,string[] sourcecolumns,string method,double cp)
 {
     AppDomain domain = AppDomain.CreateDomain(Guid.NewGuid().ToString());
     string name = Guid.NewGuid().ToString();
     var root = new DirectoryInfo(System.Windows.Forms.Application.StartupPath + "\\..\\Temp");
     if (!root.Exists)
         root.Create();
     string fullimagepath = root.FullName + "\\" + name + ".png";
     string fulltextpath = root.FullName + "\\" + name + ".txt";
     byte[] buffer =null;
     string result = "";
     double[] tempd;
     string[] temps;
     double[,] cptable = null;
     try
     {
         int rcount = data.RowCount;
         int ccount = sourcecolumns.Length+1;
         int i;
         List<double[]> sourcedata = new List<double[]>();
         Dictionary<string, double[]> doubledata = new Dictionary<string, double[]>();
         Dictionary<string, string[]> stringdata = new Dictionary<string, string[]>();
         var type = data.GetColumnType(targetcolumn);
         if (type == typeof(double) || type == typeof(int) || type == typeof(decimal) || type == typeof(float))
         {
             tempd = new double[rcount];
             for (i = 0; i < rcount; i++)
                 tempd[i] = data[i, targetcolumn].ConvertToDouble();
             doubledata.Add(targetcolumn, tempd);
         }
         else
         {
             temps = new string[rcount];
             for (i = 0; i < rcount; i++)
                 temps[i] = data[i, targetcolumn].ToString();
             stringdata.Add(targetcolumn, temps);
         }
         foreach(var sourcecolumn in sourcecolumns)
         {
             type = data.GetColumnType(sourcecolumn);
             if (type == typeof(double) || type == typeof(int) || type == typeof(decimal) || type == typeof(float))
             {
                 tempd = new double[rcount];
                 for (i = 0; i < rcount; i++)
                     tempd[i] = data[i, sourcecolumn].ConvertToDouble();
                 doubledata.Add(sourcecolumn, tempd);
             }
             else
             {
                 temps = new string[rcount];
                 for (i = 0; i < rcount; i++)
                     temps[i] = data[i, sourcecolumn].ToString();
                 stringdata.Add(sourcecolumn, temps);
             }
         }
         if (!RpartMethod.Contains(method.ToLower()))
             throw new Exception("不支持的方法参数");
         cptable = (domain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(Rpart).FullName) as Rpart).BaseStart(root.FullName, name, width, height, targetcolumn, sourcecolumns, doubledata, stringdata, method.ToString().ToLower(),cp);
         using (FileStream fs = new FileStream(fullimagepath, FileMode.Open))
         {
             buffer = new byte[fs.Length];
             fs.Read(buffer, 0, buffer.Length);
         }
         using (StreamReader sr = new StreamReader(fulltextpath,Encoding.Default))
         {
             result = sr.ReadToEnd();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         AppDomain.Unload(domain);
         File.Delete(fullimagepath);
         File.Delete(fulltextpath);
     }
     return new Tuple<Image,string,double[,]>(Image.FromStream(new MemoryStream(buffer)),result,cptable);
 }
开发者ID:supergfox,项目名称:SPC,代码行数:80,代码来源:Access.cs


注:本文中的IDataTable.GetColumnType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。