我想将表格数据从我的应用程序复制到 Excel。到目前为止,我发现的最简单的方法是使用 HTML 作为中间格式。阅读此问题后,我可以保留数据的格式。有没有办法保持列的宽度?我尝试以各种方式设置样式:
<td style="width:100;">...</td>
<td style="width:100px;">...</td>
<td style="width:100pt;">...</td>
Run Code Online (Sandbox Code Playgroud)
但无济于事。有任何想法吗?
对于加分,是否有可以找到 Excel 的 HTML“格式”描述的地方?
[编辑] 更新:我编写了一个小工具来转储传输类型“XML 样式表”。这是一个自包含的 XML 文档。它还包含列宽。但是快速测试表明 Excel 完全忽略了列宽,即使我在两个表之间进行剪切和粘贴 :( 因此,除非有人可以告诉我更改此行为的选项,否则我想在粘贴时根本不可能格式化列。
[EDIT2] 我找到了一种方法。粘贴后,您会在右下角看到一个小图标,看起来像工具栏中的粘贴按钮。在这里,您可以选择一些选项。一种是“保持源表的宽度”。
请有人解释一下ViewState,应用程序和页面会话之间的区别吗?
我一直主张无状态网络,但想知道有状态网络的拥护者在说什么.
你是否有任何有状态比无国籍更合适的情况?
bool IsTypeAGenericList(Type listType)
{
typeof(IList<>).IsAssignableFrom(listType.GetGenericTypeDefinition())
}
Run Code Online (Sandbox Code Playgroud)
给定时返回false typeof(List<int>).
我假设这是因为两个类型参数可以不同,对吗?
从Python到C#的异常处理让我烦恼的一件事是,在C#中似乎没有任何指定else子句的方法.例如,在Python中我可以写这样的东西(注意,这只是一个例子.我不是问什么是读取文件的最佳方法):
try
{
reader = new StreamReader(path);
}
catch (Exception)
{
// Uh oh something went wrong with opening the file for reading
}
else
{
string line = reader.ReadLine();
char character = line[30];
}
Run Code Online (Sandbox Code Playgroud)
从我在大多数C#代码中看到的,人们只会写下面的内容:
try
{
reader = new StreamReader(path);
string line = reader.ReadLine();
char character = line[30];
}
catch (Exception)
{
// Uh oh something went wrong, but where?
}
Run Code Online (Sandbox Code Playgroud)
这样做的问题在于我不希望因为文件中的第一行不能包含超过30个字符而超出范围异常.我只想捕获与读取文件流有关的异常.我可以在C#中使用任何类似的构造来实现相同的功能吗?
从SQL Server中的datetime字段中删除时间部分时,哪种方法提供了最佳性能?
a) select DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0)
Run Code Online (Sandbox Code Playgroud)
要么
b) select cast(convert(char(11), getdate(), 113) as datetime)
Run Code Online (Sandbox Code Playgroud)
第二种方法确实发送了更多的字节,但这可能没有转换速度那么重要.
两者似乎都非常快,但在处理数十万或更多行时速度可能会有所不同?
另外,是否有可能有更好的方法来摆脱SQL中日期时间的时间部分?
似乎默认情况下Catalyst不输出Cache-Control:等标题.我知道我可以在给定的控制器方法中输出它们,如下所示:
$c->response->headers->last_modified(time);
$c->response->headers->expires(time + $self->{cache_time});
$c->response->headers->header(cache_control => "public, max-age=$self->{cache_time}");
Run Code Online (Sandbox Code Playgroud)
不过,在每种方法中做到这一点都会非常痛苦!我更喜欢的是:
有没有一个很好的方法来实现这一目标?
我需要将键/对对添加到字典中,但我当然需要首先检查密钥是否已经存在,否则我得到" 密钥已存在于字典中 "错误.下面的代码解决了这个问题,但很笨重.
在没有像这样的字符串帮助方法的情况下,这样做更优雅的方法是什么?
using System;
using System.Collections.Generic;
namespace TestDictStringObject
{
class Program
{
static void Main(string[] args)
{
Dictionary<string, object> currentViews = new Dictionary<string, object>();
StringHelpers.SafeDictionaryAdd(currentViews, "Customers", "view1");
StringHelpers.SafeDictionaryAdd(currentViews, "Customers", "view2");
StringHelpers.SafeDictionaryAdd(currentViews, "Employees", "view1");
StringHelpers.SafeDictionaryAdd(currentViews, "Reports", "view1");
foreach (KeyValuePair<string, object> pair in currentViews)
{
Console.WriteLine("{0} {1}", pair.Key, pair.Value);
}
Console.ReadLine();
}
}
public static class StringHelpers
{
public static void SafeDictionaryAdd(Dictionary<string, object> dict, string key, object view)
{
if (!dict.ContainsKey(key))
{
dict.Add(key, view);
}
else
{
dict[key] = view; …Run Code Online (Sandbox Code Playgroud) c# ×3
collections ×2
.net ×1
asp.net ×1
c++ ×1
caching ×1
catalyst ×1
date ×1
datetime ×1
debugging ×1
dictionary ×1
excel ×1
gcc ×1
generics ×1
html ×1
html-table ×1
http-headers ×1
import ×1
perl ×1
python ×1
sql ×1
sql-server ×1
state ×1
t-sql ×1
width ×1