3

Python-Excel xlwt を使用して、スプレッドシートに入力するための空白の Excel スプレッドシートを作成しています。特定の範囲のセルを日付形式にするように指定したいと思います。私は次のようなことをしています:

datestyle = xlwt.XFStyle()
datestyle.num_format_str = "YYYY-MM-DD"
ws.write(row, column, "", datestyle)

しかし、それは少し過度に規範的です。人々はデータを貼り付けている可能性があります。つまり、形式が正確に一致しない場合、問題が発生します。スプレッドシートは一般に、さまざまな形式で貼り付けられた日付を見つけて理解するのに適しています。特定の入力形式に制限されることなく、スプレッドシートでこれを実行できるようにしたいと考えています。

「このセルは日付です」と言いたいだけで、フォーマットを課すことはありません。これは実行可能ですか?

4

2 に答える 2

2

You can't specify that a cell is a date and not impose a format, not with xlwt and not with anything else, including Excel itself. Two reasons:

(1) You can't specify that a cell is any type. It is whatever the user types or pastes in. You can format it as a date but they can type in text.

(2) "date" is not a data type in Excel. All Excel knows about is text, floating point numbers, booleans (TRUE/FALSE), errors (#DIV/0 etc), and "blank" (formatting but no data). A date cell is just a number cell with a date format.

A general answer to "Can I do X with xlwt?" questions: Firstly try doing X with Excel / OpenOffice Calc / Gnumeric. If you can't, then neither can xlwt.

于 2011-06-29T20:27:28.487 に答える
2

処方している形式は、日付の表示方法を定義しますが、Excel が入力された日付を解釈する方法には影響しません。形式が YYYY-MM-DD の場合、ユーザーは引き続き 5/21/2008 を入力でき、文字列は日付値 (39589) に変換され、指定した形式で表示されます: "2008-01-21"

于 2011-06-29T17:35:34.287 に答える