Commits

Eric Gazoni committed e009f2d

[writer] apply Jun Omae fix for Boolean values (fixes #58)

  • Participants
  • Parent commits 194fcf0

Comments (0)

Files changed (4)

File openpyxl/tests/test_data/writer/expected/sheet1_bool.xml

+<?xml version='1.0' encoding='UTF-8'?>
+<worksheet xml:space="preserve" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
+    <sheetPr>
+        <outlinePr summaryBelow="1" summaryRight="1" />
+    </sheetPr>
+    <dimension ref="A1:F43" />
+    <sheetViews>
+        <sheetView workbookViewId="0">
+            <selection activeCell="A1" sqref="A1" />
+        </sheetView>
+    </sheetViews>
+    <sheetFormatPr defaultRowHeight="15" />
+    <cols>
+        <col collapsed="0" max="6" min="6" width="9.10" />
+    </cols>
+    <sheetData>
+        <row r="42" spans="1:6">
+            <c r="F42" t="b">
+                <v>0</v>
+            </c>
+        </row>
+        <row r="43" spans="1:6">
+            <c r="F43" t="b">
+                <v>1</v>
+            </c>
+        </row>
+    </sheetData>
+</worksheet>

File openpyxl/tests/test_write.py

             'sheet1.xml'), content)
 
 
+def test_write_bool():
+    wb = Workbook()
+    ws = wb.create_sheet()
+    ws.cell('F42').value = False
+    ws.cell('F43').value = True
+    content = write_worksheet(ws, {}, {})
+    assert_equals_file_content(os.path.join(DATADIR, 'writer', 'expected', \
+            'sheet1_bool.xml'), content)
+
+
 def test_write_formula():
     wb = Workbook()
     ws = wb.create_sheet()

File openpyxl/writer/dump_worksheet.py

             if dtype == 'formula':
                 tag(doc, 'f', body = '%s' % cell[1:])
                 tag(doc, 'v')
+            elif dtype == 'boolean':
+                tag(doc, 'v', body = '%d' % cell)
             else:
                 tag(doc, 'v', body = '%s' % cell)
             

File openpyxl/writer/worksheet.py

                 tag(doc, 'v')
             elif cell.data_type == cell.TYPE_NUMERIC:
                 tag(doc, 'v', body = repr(value))
+            elif cell.data_type == cell.TYPE_BOOL:
+                tag(doc, 'v', body = '%d' % value)
             else:
                 tag(doc, 'v', body = '%s' % value)
             end_tag(doc, 'c')