0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Excelにコピペができない場合はNULL文字を疑う

Last updated at Posted at 2025-04-05

事象

次のようなテキストファイルがあるとします。

image.png

このテキストを全選択し、Excelにコピー&ペーストしたところ、途中までしかExcelにコピーされませんでした。

image.png

原因

原因はNULL文字です。Rubyを利用して、文字の中身をインスペクションしてみましょう。

$ cat input.txt | ruby -n -e 'p $_'
"ABC DEF\u0000GHI"

DEFとGHIの間にあるのは一見すると、単なる空白に見えますが、実際はNULL文字でした。そのため、ExcelはDEFで文字列が終了していると判定し、それ以降を切り捨ててしまったのです。

対応方法としてはいろいろ考えられますが、今回はNULL文字をコピペ可能な文字に置換することで対応しました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?