在 Excel 中,当小于第 12 天时,远程网站日月反转?

发布于 2024-10-17 19:31:41 字数 1897 浏览 2 评论 0原文

本地机器视觉工作室的日期和月份的格式为 dd/mm/yyyy。 但是部署到远程网站后,使用C#保存Excel,不到第12天,就变成了mm/dd/yyyy。

实际上代码是从执行数据透视表的存储过程将数据获取到Excel中

我将日期保存到单元格的方式是

oSheet.Cells[currentline, i + 1] = String.Format("{0:dd-MM-yyyy}", Convert.ToDateTime(reader[i].ToString()));

while (reader.Read())
{
    for (int i = 0; i < reader.FieldCount; i++)
    {
        if (reader[i] != System.DBNull.Value)
        {
            if (i == 0)
            {
                oSheet.Cells[currentline, i + 1] = String.Format("{0:dd-MM-yyyy}", Convert.ToDateTime(reader[i].ToString()));

            }
            else
                oSheet.Cells[currentline, i + 1] = reader[i].ToString();
        }
    }
    currentline = currentline + 1;
}
reader.Close();

        <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
                <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
                <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
            </dependentAssembly>
        </assemblyBinding>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Office.Interop.Excel"
        publicKeyToken="71e9bce111e9429c"
        culture="neutral" />
        <publisherPolicy apply="yes" />
        <bindingRedirect oldVersion="12.0.0.0"
        newVersion="11.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

Local machine visual studio day and month are normal in format dd/mm/yyyy.
But after deployed to remote web site, saved Excel using C#, less than day 12, become mm/dd/yyyy.

Actually the code is to get data into Excel from stored procedure which do pivot table

The way i save date to cell is

oSheet.Cells[currentline, i + 1] = String.Format("{0:dd-MM-yyyy}", Convert.ToDateTime(reader[i].ToString()));

while (reader.Read())
{
    for (int i = 0; i < reader.FieldCount; i++)
    {
        if (reader[i] != System.DBNull.Value)
        {
            if (i == 0)
            {
                oSheet.Cells[currentline, i + 1] = String.Format("{0:dd-MM-yyyy}", Convert.ToDateTime(reader[i].ToString()));

            }
            else
                oSheet.Cells[currentline, i + 1] = reader[i].ToString();
        }
    }
    currentline = currentline + 1;
}
reader.Close();

        <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
                <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
                <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
            </dependentAssembly>
        </assemblyBinding>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Office.Interop.Excel"
        publicKeyToken="71e9bce111e9429c"
        culture="neutral" />
        <publisherPolicy apply="yes" />
        <bindingRedirect oldVersion="12.0.0.0"
        newVersion="11.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑着哭最痛 2024-10-24 19:31:41

我添加后解决了
UICulture="en" Culture="en-GB" 在 aspx 中

i solved after i add
UICulture="en" Culture="en-GB" in aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文