2

私はPython 2.7.3を使用しています.openpyxlライブラリによってローカル画像へのハイパーリンクをセルに書き込む必要があります.

Web サイトにハイパーリンクを追加する必要がある場合は、次のように記述します。

openpyxlインポートワークブックから

wb = Workbook()

dest_filename = r'empty_book.xlsx'

ws = wb.worksheets[0]

ws.title = 'Name'

hyperlink to local picture

ws.cell('B1').hyperlink = ('http://pythonhosted.org/openpyxl/api.html')

hyperlink to local picture

ws.cell('B2').hyperlink = ('1.png') # It doesn't work! 

wb.save(filename = dest_filename)

3 つの質問があります。

  1. VBA のスタイル関数のようなハイパーリンクを記述する方法: ハイパーリンク ActiveCell.FormulaR1C1 = _ "=HYPERLINK(""http://stackoverflow.com/questions/ask"",""site"")" と彼女の名前を使用
  2. ローカル画像へのハイパーリンクを書き込むにはどうすればよいですか? ws.cell('B2').hyperlink = ('1.png') # It doesn't work! And I don't now what to do ) Plese, help me )
  3. Unicode ハイパーリンクを画像に使用できますか? たとえば、私が使用するとき ws.cell('B1').hyperlink = (u'http://pythonhosted.org/openpyxl/api.html') It fail with error! for example we have picture 'russian_language_name.png' and we create hyperlink in exel without any problem. We click to the cell, and then print '=Hyperlink("http://stackoverflow.com/questions/ask";"site_by_russian_language")

ドキュメントを保存し、解凍します。次に、彼のディレクトリにある xl->worksheets->sheet1.xml に移動すると、タイトルが表示されます

<?xml version="1.0" encoding="UTF-8" standalone="true"?>

その後 ...

row r="2" x14ac:dyDescent="0.25" spans="2:6">-<c r="B2" t="str" s="1"><f>HYPERLINK("http://stackoverflow.com/questions/ask","site_by_russian_language")</f><v>site_by_russian_language</v></c>

すべてOK =) ExelはUnicodeをサポートしていますが、Pythonのライブラリopenpyxlはどうですか? ハイパーリンクでユニコードをサポートしていますか?

4

3 に答える 3

0

ファイル内のファイルはエンコードされた.xlsxXML ファイルであるため、Unicode ハイパーリンクは問題になりません。UTF-8

于 2013-03-19T07:37:42.283 に答える