简体   繁体   English

使用 SSIS 读取 Excel 时的日期格式

[英]Date Formats When Reading Excel with SSIS

experts.专家。 I've got two similar Excel files (xlsm) as templates.我有两个类似的 Excel 文件(xlsm)作为模板。 Both have sheets with Date column.两者都有日期列的工作表。 Visible format for both files when use Excel is "10-Aug-20".使用 Excel 时两个文件的可见格式为“10-Aug-20”。 But when I read these files with SSIS process with Script Component Source using Microsoft.ACE.OLEDB.12.0 with "IMEX=1"... ta-da.., some I see as expected.但是,当我使用带有“IMEX = 1”的 Microsoft.ACE.OLEDB.12.0 的脚本组件源的 SSIS 进程读取这些文件时...... ta-da..,有些我看到了预期。 but some are 10.08:2020 00:00.00 This causes me a lot of pain because I will process files from both US (MM/dd/yyyy) and German (dd.MM.yyyy) date formats and would like to have locale-independent date format to process dates same way.但有些是 10.08:2020 00:00.00 这让我很痛苦,因为我将处理来自美国 (MM/dd/yyyy) 和德国 (dd.MM.yyyy) 日期格式的文件,并且希望拥有独立于语言环境的文件日期格式以相同的方式处理日期。 How can I force excel to give or ssis to read a correct date format.如何强制 excel 给出或 ssis 读取正确的日期格式。

Any suggestion how to see both files same programmaticly is most wanted and highly appreciated!任何关于如何以编程方式查看两个文件的建议都是最需要和高度赞赏的!

You could try to use the script component (as Transformation) to transform the data by using DateTime.TryParseExact您可以尝试使用脚本组件(作为转换)通过使用DateTime.TryParseExact来转换数据

  string dateString = "10-Aug-20";
  string format = "dd-MMM-yy";
  DateTime dateTime;
  if (DateTime.TryParseExact(dateString, format, "en-US",DateTimeStyles.None, out dateTime))//if (DateTime.TryParseExact(dateString, format, "de-DE",DateTimeStyles.None, out dateTime))
        {
            Console.WriteLine(dateTime);
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM