예제 #1
0
import os
import sys
from xlwt import *

from base import from_this_dir

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
#to write a simple file you just need the xlwt package.


wb = Workbook() # create empty workbook object
newsheet = wb.add_sheet('my_first_spreadsheet') #adding and renaming a column

newsheet.write(0,0,'Hello') #write in the first cel A1
newsheet.write(0,1,'World!') #write in B1
newsheet.write(1,0,'I am') #write in A2
newsheet.write(1,1,'learning') #write in B2

wb.save(from_this_dir('01_simple_basic.xls'))
예제 #2
0
#################################################################################

#function to populate columns
def populating_column(list_of_items, newsheet):

	i=0
	for item in list_of_items:
		newsheet.write(0,i,item)
		i=i+1

#function to populate rows
def populating_row(list_of_items, newsheet):

	j=0
	for item in list_of_items:
		newsheet.write(j,0,item)
		j=j+1


#creating excel file
wb = Workbook() # create empty workbook object
my_list = ['First column', 'Second Column', 'Third Column', 'Fourth Column']#creating a list

newsheet = wb.add_sheet('my_first_spreadsheet') #adding and renaming a column
populating_column(my_list, newsheet)

second_spreadsheet = wb.add_sheet('my_second_spreadsheet') #adding and renaming a column
populating_row(my_list, second_spreadsheet)

wb.save(from_this_dir('02_simple_basic_loop.xls'))
예제 #3
0
import os
import sys
from xlwt import *

from base import from_this_dir

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
#to write a simple file you just need the xlwt package.


wb = Workbook() # create empty workbook object
newsheet = wb.add_sheet('my_first_spreadsheet') #adding and renaming a column

#writing labels
newsheet.write(0,0,'number') #write in the first cel A1
newsheet.write(0,1,'square') #write in B1
newsheet.write(0,2,'is a even number?') #write in C1

#creating a list

list_numbers = list(xrange(100))

for item in list_numbers:
	newsheet.write(i,0,item) #write in column A
	i=i+1


wb.save(from_this_dir('04_formula.xls'))
예제 #4
0
	def getWorkBook(self,fname):
		#可以将formatting_info参数设置为false试试
		self.book = xlrd.open_workbook(from_this_dir(fname), formatting_info=True)
예제 #5
0
 def setUp(self):
     self.book = open_workbook(from_this_dir('test.xlsx'))