将 CR+LF 复制并粘贴到 Excel 电子表格中时出现问题,需要软段落 (Alt+Enter)

发布于 2024-08-19 22:04:51 字数 781 浏览 5 评论 0原文

我正在尝试将我们软件中创建的表格复制到 Excel 电子表格中。

我们应用程序中的一些标题标题太大,无法放入一列中,因此它们由 #13+#10 (CR+LF) 分隔,因此它们位于下一行。例如,

Strain  SpikeConc  Spike
        ng/g       dpm/g
-------------------------
Blah    20.0       50.1
Blah2   22.1       60.2

但是,当将其复制到 Excel 中时,我们会发生奇怪的事情。 CR+LF 被解释为(你猜对了)新行请求。因此我们得到的东西看起来完全错误。例如,

Strain  SpikeConc
ng/g    Spike
dmp/g
-------------------------
Blah    20.0       50.1
Blah    22.1       60.2

它错误地解释了 SpikeConc 后的 CR+LF 并在新单元格中创建新行,而不是像按 Alt+Enter 并在同一单元格中为您提供新行那样创建软段落。

有人知道如何编码软段落而不是新行吗?

我尝试过单独使用 CR (#13) 和 LF (#10),但它们都有相同的行为。

我相信有一些 unicode 字符

LS:行分隔符,U+2028

PS:段落分隔符,U+2029

但我似乎找不到如何将它们编码到我的应用程序中的表中。

PS我们使用的是Delphi6(不要问)

I'm trying to copy a table that is created in our software into an excel spreadsheet.

Some of the title headers in our application are too big to fit in a column so they are separated by a #13+#10 (CR+LF) so they sit on the next line. e.g.

Strain  SpikeConc  Spike
        ng/g       dpm/g
-------------------------
Blah    20.0       50.1
Blah2   22.1       60.2

However, when this is copied into excel we get a strange thing happening. The CR+LF is interpreted as (you guessed it) a new line request. Hence we get something that looks totally wrong. e.g.

Strain  SpikeConc
ng/g    Spike
dmp/g
-------------------------
Blah    20.0       50.1
Blah    22.1       60.2

It is interpreting the CR+LF after the SpikeConc incorrectly and creating a new line in a new cell instead of creating a soft paragraph like you would get if you pressed Alt+Enter and giving you a new line in the same cell.

Anyone got any ideas how to encode a soft paragraph rather than a new line?

I've tried using just CR (#13) on it's own and just LF (#10) on it's own but they both have the same behaviour.

I believe there are some unicode characters

LS: Line Separator, U+2028

PS: Paragraph Separator, U+2029

but I can't seem to find how to encode them into the table in my App.

PS We're using Delphi6 (don't ask)

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

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

发布评论

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

评论(2

我做我的改变 2024-08-26 22:04:51

太棒了。如果我这样写,

"SpikeConc #13+#10 ng/g" 

它会在 Excel 中正确显示,

SpikeConc
ng/g

谢谢。这让我发疯。

That's Brilliant. If I put it like this

"SpikeConc #13+#10 ng/g" 

it displays it correctly in excel like this

SpikeConc
ng/g

Thanks. That was driving me crazy.

我还不会笑 2024-08-26 22:04:51

正如评论中提到的,这是我们用来剥离 CR 的函数。无论是使用此方法还是将字符串括在双引号中都足以在 Excel 中实现软返回。

function RemoveCr(const Value: string): string;
  var
    I, J: Integer;
  begin
    J := 0;
    SetLength(Result, Length(Value));
    for I := 1 to Length(Value) do
      if Value[I] <> #13 then
      begin
        Inc(J);
        Result[J] := Value[I];
      end;
    SetLength(Result, J);
  end;

As mentioned in the comments, this is the function we use to strip the CR's. Either this or enclosing the string in double quotes suffices to have a soft return in excel.

function RemoveCr(const Value: string): string;
  var
    I, J: Integer;
  begin
    J := 0;
    SetLength(Result, Length(Value));
    for I := 1 to Length(Value) do
      if Value[I] <> #13 then
      begin
        Inc(J);
        Result[J] := Value[I];
      end;
    SetLength(Result, J);
  end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文