예제 #1
0
        protected override void Execute(CodeActivityContext context)
        {
            Encoding csvEncoding;
            string   filePath     = PathUrl.Get(context);
            string   encodingType = EncodingType.Get(context);
            string   delimiter    = ",";

            if (Delimiter == DelimiterEnums.Caret插入符号)
            {
                delimiter = "^";
            }
            else if (Delimiter == DelimiterEnums.Comma逗号)
            {
                delimiter = ",";
            }
            else if (Delimiter == DelimiterEnums.Pipe竖线)
            {
                delimiter = "|";
            }
            else if (Delimiter == DelimiterEnums.Semicolon分号)
            {
                delimiter = ";";
            }
            else if (Delimiter == DelimiterEnums.Tab制表符)
            {
                delimiter = "	";
            }

            if (!File.Exists(filePath))
            {
                // 文件不存在,请检查路径有效性
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, Localize.LocalizedResources.GetString("xFileNotExist"));
                return;
            }

            /*取字符编码 如果为空则取文件编码 异常则取系统默认编码*/
            try
            {
                if (encodingType == null)
                {
                    csvEncoding = CSVEncoding.GetEncodingType(filePath);
                }
                else
                {
                    csvEncoding = Encoding.GetEncoding(encodingType);
                }
            }
            catch (Exception)
            {
                csvEncoding = System.Text.Encoding.Default;
            }

            /*将DataTable内容写入CSV文件*/
            try
            {
                DataTable inDataTable = InDataTable.Get(context);
                WriteCSVFile(inDataTable, filePath, csvEncoding, delimiter);
            }
            catch (Exception e)
            {
                // EXCEL执行过程出错
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, Localize.LocalizedResources.GetString("xExcelExecError"), e.Message);
                throw e;
            }
        }
예제 #2
0
        protected override void Execute(CodeActivityContext context)
        {
            Encoding csvEncoding;
            string   filePath     = PathUrl.Get(context);
            string   encodingType = EncodingType.Get(context);
            string   delimiter    = ",";

            if (Delimiter == DelimiterEnums.Caret插入符号)
            {
                delimiter = "^";
            }
            else if (Delimiter == DelimiterEnums.Comma逗号)
            {
                delimiter = ",";
            }
            else if (Delimiter == DelimiterEnums.Pipe竖线)
            {
                delimiter = "|";
            }
            else if (Delimiter == DelimiterEnums.Semicolon分号)
            {
                delimiter = ";";
            }
            else if (Delimiter == DelimiterEnums.Tab制表符)
            {
                delimiter = "	";
            }

            if (!File.Exists(filePath))
            {
                // 文件不存在,请检查路径有效性
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, Localize.LocalizedResources.GetString("xFileNotExist"));
                return;
            }

            /*取字符编码 如果为空则取文件编码 异常则取系统默认编码*/
            try
            {
                if (encodingType == null)
                {
                    csvEncoding = CSVEncoding.GetEncodingType(filePath);
                }
                else
                {
                    csvEncoding = Encoding.GetEncoding(encodingType);
                }
            }
            catch (Exception)
            {
                csvEncoding = System.Text.Encoding.Default;
            }

            /*设置DataTable*/
            try
            {
                DataTable dataTable = ReadCSVFile(filePath, csvEncoding, delimiter);
                OutDataTable.Set(context, dataTable);
                foreach (DataRow dr in dataTable.Rows)
                {
                    for (int i = 0; i < dataTable.Columns.Count; i++)
                    {
                        System.Diagnostics.Debug.WriteLine("dt : " + dr[i]);
                    }
                }
            }
            catch (Exception e)
            {
                // EXCEL执行过程出错
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, Localize.LocalizedResources.GetString("xExcelExecError"), e.Message);
                throw e;
            }
        }