I presume that you mean that the above statement causes general_address to refer to a string (str or unicode object).
Just so that we're absolutely sure, please execute the following statement: print type(general_address), repr(general_address) and reply back with a copy/paste of the output.
> i want to print the "general address" as my column heading in my xls > sheet. i dnt want to hardcode it in the sheet.write.
Of course you don't want to hardcode it .... what is wrong with doing this: # Assuming for purposes of the example that you want this # to appear in cell C1 worksheet.write(0, 2, general_address) ?
> i want to print the "general address" as my column heading in my xls > sheet. i dnt want to hardcode it in the sheet.write.
This is really a Django question, but since I've recently done something similar myself...
If you're starting off with an object, you'd do:
model = object.__class__
If you already have a model, you'd then do:
names = [] headings = [] for field in model._meta.fields: if name=='id': # you may want to skip auto-generated primary keys continue if getattr(f,'related',None) is not None: # you may want to skip foreign keys continue names.append(field.name) headings.append(field.verbose_name)
The to dump, for example, all the instances of this model to a file, you'd do:
from xlwt import Workbook book = Workbook() sheet = book.add_sheet(YourModel.__name__+' instances')
for col,heading in enumerate(headings): sheet.write(0,col,heading)
for row,obj in enumerate(YouModel.objects.all()): for col,name in enumerate(names): sheet.write(row+1,col,getattr(obj,name))
> I presume that you mean that the above statement causes general_address
> to refer to a string (str or unicode object).
> Just so that we're absolutely sure, please execute the following statement:
> print type(general_address), repr(general_address)
> and reply back with a copy/paste of the output.
> > i want to print the "general address" as my column heading in my xls
> > sheet. i dnt want to hardcode it in the sheet.write.
> Of course you don't want to hardcode it .... what is wrong with doing this:
> # Assuming for purposes of the example that you want this
> # to appear in cell C1
> worksheet.write(0, 2, general_address)
> ?
danin wrote: > address_general = models.CharField(_('Address'), max_length = 100, > blank = True,null=True) > This is my exact line from model
Danin,
Please be aware that it takes quite a psychic leap to guess that you are talking about a Django model here.
This is *not* the Django list and most of the people on this list do not know or care what Django is ;-) I've tried to provide help as best I can in my other reply, but if you have Django questions you're likely to get better help on the Django list:
> danin wrote:
> > address_general = models.CharField(_('Address'), max_length = 100,
> > blank = True,null=True)
> > This is my exact line from model
> Danin,
> Please be aware that it takes quite a psychic leap to guess that you are
> talking about a Django model here.
> This is *not* the Django list and most of the people on this list do not
> know or care what Django is ;-) I've tried to provide help as best I can
> in my other reply, but if you have Django questions you're likely to get
> better help on the Django list:
John Yeung wrote: > Maybe he got the message that the Django group is a better place for > his inquiries than the Python Excel group? (We can hope, right? :)
> Or, perhaps your earlier code examples were enough to get him where he > needed to go.
Yeah, I just get frustrated with people rude enough to post their half formed and semi incomprehensible questions and, when the mind reading does actually work, who then bugger off without ever even explaining what happened...