SlideShare a Scribd company logo
#!/bin/env python
                                                                                       pyExcelerator/xlwt Cheatsheet
                                                                                                # Border                                                             def get_font(values):
"""Executable cheatsheet illustrating use of pyExcelerator and its                                                                                                       """
                                                                                                write(ws, 0, 2, "Border",
fork, xlwt                                                                                                                                                               'height' 10pt = 200, 8pt = 160
                                                                                                      {"border": (("bottom",pycel.Formatting.Borders.THIN),
                                                                                                                  ("bottom_colour", YELLOW))})                           """
I recommend using xlwt which is a somewhat unknown fork of                                                                                                               font_key = values
pyExcelerator. There are examples shipped with both projects, use                                                                                                        f = FONT_FACTORY.get(font_key, None)
them if necessary, but the source is usually your best friend. The                                                                                                       if f is None:
                                                                                                # Wrapping
libraries are quite capable but don't support charting. xlwt also as
                                                                   h                                                                                                         f = pycel.Font()
                                                                                                write(ws, 0, 3, "A bunch of long text to wrap",
a mailing list that is active here:                                                                                                                                          for attr, value in values:
                                                                                                      {"alignment":(("wrap", pycel.Alignment.WRAP_AT_RIGHT),)})
http://groups.google.com.au/group/python-excel                                                                                                                                    f.__setattr__(attr, value)
                                                                                                # Set column width                                                           FONT_FACTORY[font_key] = f
Another good link is here:                                                                                                                                               return f
                                                                                                # (see pycel.BIFFRecords.ColInfoRecord for details, width in
http://ntalikeris.blogspot.com/2007/10/create-excel-file-with-python
                                                                   -my-sort.html
                                                                                                # 1/256th of zero character)
                                                                                                write(ws, 0, 4, "A bunch of longer text not wrapped
                                                                                                                                                  ")                 if __name__ == "__main__":
This illustrates common usage for .xls generation, but also uses                                                                                                         create_spreadsheet()
                                                                                                ws.col(4).width = len("A bunch of longer text not wrapped
                                                                                                                                                        ")*256
factories to limit object creation of styles (which can crash Excel)
                                                                   .
It's meant to show example, but for more details, I recommend the
                                                                                                # Freeze/split headers when scrolling
sources I mention above.
                                                                                                write(ws, 0, 5, "Header")
                                                                                                ws.panes_frozen = True
Please send comments/suggestions my way
                                                                                                ws.horz_split_pos = 1
                                                                                                for row in range(1, 200):
author: matthewharrison@gmail.com
                                                                                                    write(ws, row, 5, row)
"""
                                                                                                # Save the workbook
#import pyExcelerator as pycel
                                                                                                wb.save("out.xls")
import xlwt as pycel
                                                                                            def write(ws, row, col, data, style
                                                                                                                              =None):
# Excel has issues when creating too many styles/fonts, hence use
                                                                                                """
# a factory to reuse instances (see FAQ#13 http://poi.apache.org/faq
                                                                   .html )
                                                                                                Write data to row, col of worksheet (ws) using the style
STYLE_FACTORY = {}
                                                                                                information.
FONT_FACTORY = {}
                                                                                                Again, I'm wrapping this because you'll have to do it if you
def create_spreadsheet():
                                                                                                create large amounts of formatted entries in your spreadsheet
    # Create a workbook
                                                                                                (else Excel, but probably not OOo will crash).
    wb = pycel.Workbook()
                                                                                                """
                                                                                                if style:
   # Add a sheet
                                                                                                    s = get_style(style)
   ws = wb.add_sheet("Example Sheet")
                                                                                                    ws.write(row, col, data, s)
                                                                                                else:
   # Tweak printer settings
                                                                                                    ws.write(row, col, data)
   # following makes a landscape layout on Letter paper
   # the width of the columns
                                                                                            def get_style(style):
   ws.fit_num_pages = 1
                                                                                                """
   ws.fit_height_to_pages = 0
                                                                                                Style is a dict maping key to values.
   ws.fit_width_to_pages = 1
                                                                                                Valid keys are: background, format, alignment, border
   # Set to Letter paper
   # See BiffRecords.SetupPageRecord for paper types/orientation
                                                                                                 The values for keys are lists of tuples containing (attribute,
   ws.paper_size_code = 1
                                                                                                 value) pairs to set on model instances...
   # Set to landscape
                                                                                                 """
   ws.portrait = 0
                                                                                                 print "KEY", style
                                                                                                 style_key = tuple(style.items())
   # Write some stuff using our helper function
                                                                                                 s = STYLE_FACTORY.get(style_key, None)
                                                                                                 if s is None:
   # Formatting - hint, look at Format code in OOo
                                                                                                     s = pycel.XFStyle()
   #               format cells... Numbers tab
                                                                                                     for key, values in style.items():
   # Write a percent
                                                                                                         if key == "background":
   write(ws, 0, 0, .495, {"format":"0%"})
                                                                                                             p = pycel.Pattern()
   # Write a percent with negatives red
                                                                                                             for attr, value in values:
   write(ws, 1, 0, -.495, {"format":"0%;[RED]-0%"})
                                                                                                                 p.__setattr__(attr, value)
   # Dollar amounts
                                                                                                             s.pattern = p
   write(ws, 2, 0, 10.99, {"format":'$#,##0'})
                                                                                                         elif key == "format":
                                                                                                             s.num_format_str = values
   # Font
                                                                                                         elif key == "alignment":
   # Size
                                                                                                             a = pycel.Alignment()
   write(ws, 0, 1, "Size 160(8pt)", {"font": (("height", 160),)})
                                                                                                             for attr, value in values:
   write(ws, 1, 1, "Size 200(10pt)", {"font": (("height", 200),)})
                                                                                                                 a.__setattr__(attr, value)
   # Bold
                                                                                                             s.alignment = a                                                        matthewharrison@gmail.com
   write(ws, 2, 1, "Bold text", {"font": (("bold", True),)})
                                                                                                         elif key == "border":
                                                                                                             b = pycel.Formatting.Borders()
   # Background color
   # See http://groups.google.com.au/group/python-excel/attach/93621400
                                                                      bdddf464/palette_trial.xls?part=2
                                                                                                             for attr, value in values:                           Creative Commons Attribution 3.0 License.
                                                                                                                 b.__setattr__(attr, value)
   # for colour indices
                                                                                                             s.borders = b
   YELLOW = 5
                                                                                                         elif key == "font":
   write(ws, 3, 1, "Yellow (5) Background ",
                                                                                                             f = get_font(values)
          {"background": (("pattern", pycel.Pattern.SOLID_PATTERN),
                                                                                                             s.font = f
                           (
                           "pattern_fore_colour", YELLOW) )})
                                                                                                     STYLE_FACTORY[style_key] = s
                                                                                                 return s

More Related Content

What's hot

php string part 3
php string part 3php string part 3
php string part 3
monikadeshmane
 
Unix ppt
Unix pptUnix ppt
Unix ppt
ashish kumar
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
Sopan Shewale
 
String variable in php
String variable in phpString variable in php
String variable in php
chantholnet
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applications
Joe Jiang
 
Perl Programming - 02 Regular Expression
Perl Programming - 02 Regular ExpressionPerl Programming - 02 Regular Expression
Perl Programming - 02 Regular Expression
Danairat Thanabodithammachari
 
lab4_php
lab4_phplab4_php
lab4_php
tutorialsruby
 
Perl Scripting
Perl ScriptingPerl Scripting
Perl Scripting
Varadharajan Mukundan
 

What's hot (8)

php string part 3
php string part 3php string part 3
php string part 3
 
Unix ppt
Unix pptUnix ppt
Unix ppt
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
String variable in php
String variable in phpString variable in php
String variable in php
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applications
 
Perl Programming - 02 Regular Expression
Perl Programming - 02 Regular ExpressionPerl Programming - 02 Regular Expression
Perl Programming - 02 Regular Expression
 
lab4_php
lab4_phplab4_php
lab4_php
 
Perl Scripting
Perl ScriptingPerl Scripting
Perl Scripting
 

Viewers also liked

Web design -_lecture_1
Web design -_lecture_1Web design -_lecture_1
Web design -_lecture_1Soyokos Soyoko
 
MySQL Э.Насанжаргал
MySQL Э.НасанжаргалMySQL Э.Насанжаргал
MySQL Э.НасанжаргалSingleton
 
P3 ELECTRICAL POWER
P3 ELECTRICAL POWERP3 ELECTRICAL POWER
P3 ELECTRICAL POWER
ScienceTutors
 
Luis Larin
Luis LarinLuis Larin
Luis Larin
nechamkin
 
Scatter Plot
Scatter PlotScatter Plot
Scatter Plot
nechamkin
 
A Sankey Framework for Energy and Exergy Flows
A Sankey Framework for Energy and Exergy FlowsA Sankey Framework for Energy and Exergy Flows
A Sankey Framework for Energy and Exergy Flows
Kamal Kannan
 
Scatter plot
Scatter plotScatter plot
Scatter plot
Manigandan Mageswaran
 
Хичээлийн тодорхойлолт
Хичээлийн тодорхойлолтХичээлийн тодорхойлолт
Хичээлийн тодорхойлолтChinzorig Undarmaa
 
Area chart
Area chartArea chart
Area chart
Mianlside
 
Web design lecture 1
Web design lecture 1Web design lecture 1
Web design lecture 1
nyamaa idesh
 
ЧСС хөтөлбөр Компьютер, интернет ашиглах
ЧСС хөтөлбөр Компьютер, интернет ашиглахЧСС хөтөлбөр Компьютер, интернет ашиглах
ЧСС хөтөлбөр Компьютер, интернет ашиглах
Herlen Byambatsogt
 
Scatter diagrams and correlation
Scatter diagrams and correlationScatter diagrams and correlation
Scatter diagrams and correlation
keithpeter
 
Scatter plots
Scatter plotsScatter plots
Scatter plots
Ms. Jones
 
интернэт програмчлал хичээлийн төлөвлөгөө
интернэт програмчлал хичээлийн төлөвлөгөөинтернэт програмчлал хичээлийн төлөвлөгөө
интернэт програмчлал хичээлийн төлөвлөгөөUsukhuu Galaa
 
Scatter Plot
Scatter PlotScatter Plot
Scatter Plot
Nishant Narendra
 
Scatter diagram
Scatter diagramScatter diagram
Scatter diagram
Roy Antony Arnold G
 
Scatter plots
Scatter plotsScatter plots
Scatter plots
swartzje
 
U.cs101 алгоритм программчлал-1(1)
U.cs101   алгоритм программчлал-1(1)U.cs101   алгоритм программчлал-1(1)
U.cs101 алгоритм программчлал-1(1)Badral Khurelbaatar
 
Scatter diagram in tqm
Scatter diagram in tqmScatter diagram in tqm
Scatter diagram in tqm
kerala universty
 
scatter diagram
 scatter diagram scatter diagram
scatter diagram
shrey8916
 

Viewers also liked (20)

Web design -_lecture_1
Web design -_lecture_1Web design -_lecture_1
Web design -_lecture_1
 
MySQL Э.Насанжаргал
MySQL Э.НасанжаргалMySQL Э.Насанжаргал
MySQL Э.Насанжаргал
 
P3 ELECTRICAL POWER
P3 ELECTRICAL POWERP3 ELECTRICAL POWER
P3 ELECTRICAL POWER
 
Luis Larin
Luis LarinLuis Larin
Luis Larin
 
Scatter Plot
Scatter PlotScatter Plot
Scatter Plot
 
A Sankey Framework for Energy and Exergy Flows
A Sankey Framework for Energy and Exergy FlowsA Sankey Framework for Energy and Exergy Flows
A Sankey Framework for Energy and Exergy Flows
 
Scatter plot
Scatter plotScatter plot
Scatter plot
 
Хичээлийн тодорхойлолт
Хичээлийн тодорхойлолтХичээлийн тодорхойлолт
Хичээлийн тодорхойлолт
 
Area chart
Area chartArea chart
Area chart
 
Web design lecture 1
Web design lecture 1Web design lecture 1
Web design lecture 1
 
ЧСС хөтөлбөр Компьютер, интернет ашиглах
ЧСС хөтөлбөр Компьютер, интернет ашиглахЧСС хөтөлбөр Компьютер, интернет ашиглах
ЧСС хөтөлбөр Компьютер, интернет ашиглах
 
Scatter diagrams and correlation
Scatter diagrams and correlationScatter diagrams and correlation
Scatter diagrams and correlation
 
Scatter plots
Scatter plotsScatter plots
Scatter plots
 
интернэт програмчлал хичээлийн төлөвлөгөө
интернэт програмчлал хичээлийн төлөвлөгөөинтернэт програмчлал хичээлийн төлөвлөгөө
интернэт програмчлал хичээлийн төлөвлөгөө
 
Scatter Plot
Scatter PlotScatter Plot
Scatter Plot
 
Scatter diagram
Scatter diagramScatter diagram
Scatter diagram
 
Scatter plots
Scatter plotsScatter plots
Scatter plots
 
U.cs101 алгоритм программчлал-1(1)
U.cs101   алгоритм программчлал-1(1)U.cs101   алгоритм программчлал-1(1)
U.cs101 алгоритм программчлал-1(1)
 
Scatter diagram in tqm
Scatter diagram in tqmScatter diagram in tqm
Scatter diagram in tqm
 
scatter diagram
 scatter diagram scatter diagram
scatter diagram
 

Similar to Cheatsheet

Unit VI
Unit VI Unit VI
EPiServer report generation
EPiServer report generationEPiServer report generation
EPiServer report generation
Paul Graham
 
lab4_php
lab4_phplab4_php
lab4_php
tutorialsruby
 
Xtext's new Formatter API
Xtext's new Formatter APIXtext's new Formatter API
Xtext's new Formatter API
meysholdt
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
keeyre
 
Bash shell programming in linux
Bash shell programming in linuxBash shell programming in linux
Bash shell programming in linux
Norberto Angulo
 
Avoiding JavaScript Pitfalls Through Tree Hugging
Avoiding JavaScript Pitfalls Through Tree HuggingAvoiding JavaScript Pitfalls Through Tree Hugging
Avoiding JavaScript Pitfalls Through Tree Hugging
zefhemel
 
Model-Driven Software Development - Pretty-Printing, Editor Services, Term Re...
Model-Driven Software Development - Pretty-Printing, Editor Services, Term Re...Model-Driven Software Development - Pretty-Printing, Editor Services, Term Re...
Model-Driven Software Development - Pretty-Printing, Editor Services, Term Re...
Eelco Visser
 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploits
hughpearse
 
Python Style Guide
Python Style GuidePython Style Guide
Python Style Guide
Jiayun Zhou
 
Reading Data into R
Reading Data into RReading Data into R
Reading Data into R
Kazuki Yoshida
 
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInScalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Vitaly Gordon
 
Puppet Camp Amsterdam 2015: The Power of Puppet 4 (Beginner)
Puppet Camp Amsterdam 2015: The Power of Puppet 4 (Beginner) Puppet Camp Amsterdam 2015: The Power of Puppet 4 (Beginner)
Puppet Camp Amsterdam 2015: The Power of Puppet 4 (Beginner)
Puppet
 
Power of Puppet 4
Power of Puppet 4Power of Puppet 4
Power of Puppet 4
Martin Alfke
 
Introduction to the rust programming language
Introduction to the rust programming languageIntroduction to the rust programming language
Introduction to the rust programming language
Nikolay Denev
 
CSS: The Boring Bits
CSS: The Boring BitsCSS: The Boring Bits
CSS: The Boring Bits
Peter Gasston
 
Real World Scalaz
Real World ScalazReal World Scalaz
Real World Scalaz
Skills Matter Talks
 
Real Work Scalaz
Real Work ScalazReal Work Scalaz
Real Work Scalaz
StackMob Inc
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by Example
Olve Maudal
 
Generic Programming
Generic ProgrammingGeneric Programming
Generic Programming
PingLun Liao
 

Similar to Cheatsheet (20)

Unit VI
Unit VI Unit VI
Unit VI
 
EPiServer report generation
EPiServer report generationEPiServer report generation
EPiServer report generation
 
lab4_php
lab4_phplab4_php
lab4_php
 
Xtext's new Formatter API
Xtext's new Formatter APIXtext's new Formatter API
Xtext's new Formatter API
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Bash shell programming in linux
Bash shell programming in linuxBash shell programming in linux
Bash shell programming in linux
 
Avoiding JavaScript Pitfalls Through Tree Hugging
Avoiding JavaScript Pitfalls Through Tree HuggingAvoiding JavaScript Pitfalls Through Tree Hugging
Avoiding JavaScript Pitfalls Through Tree Hugging
 
Model-Driven Software Development - Pretty-Printing, Editor Services, Term Re...
Model-Driven Software Development - Pretty-Printing, Editor Services, Term Re...Model-Driven Software Development - Pretty-Printing, Editor Services, Term Re...
Model-Driven Software Development - Pretty-Printing, Editor Services, Term Re...
 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploits
 
Python Style Guide
Python Style GuidePython Style Guide
Python Style Guide
 
Reading Data into R
Reading Data into RReading Data into R
Reading Data into R
 
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInScalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedIn
 
Puppet Camp Amsterdam 2015: The Power of Puppet 4 (Beginner)
Puppet Camp Amsterdam 2015: The Power of Puppet 4 (Beginner) Puppet Camp Amsterdam 2015: The Power of Puppet 4 (Beginner)
Puppet Camp Amsterdam 2015: The Power of Puppet 4 (Beginner)
 
Power of Puppet 4
Power of Puppet 4Power of Puppet 4
Power of Puppet 4
 
Introduction to the rust programming language
Introduction to the rust programming languageIntroduction to the rust programming language
Introduction to the rust programming language
 
CSS: The Boring Bits
CSS: The Boring BitsCSS: The Boring Bits
CSS: The Boring Bits
 
Real World Scalaz
Real World ScalazReal World Scalaz
Real World Scalaz
 
Real Work Scalaz
Real Work ScalazReal Work Scalaz
Real Work Scalaz
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by Example
 
Generic Programming
Generic ProgrammingGeneric Programming
Generic Programming
 

Recently uploaded

“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 

Recently uploaded (20)

“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 

Cheatsheet

  • 1. #!/bin/env python pyExcelerator/xlwt Cheatsheet # Border def get_font(values): """Executable cheatsheet illustrating use of pyExcelerator and its """ write(ws, 0, 2, "Border", fork, xlwt 'height' 10pt = 200, 8pt = 160 {"border": (("bottom",pycel.Formatting.Borders.THIN), ("bottom_colour", YELLOW))}) """ I recommend using xlwt which is a somewhat unknown fork of font_key = values pyExcelerator. There are examples shipped with both projects, use f = FONT_FACTORY.get(font_key, None) them if necessary, but the source is usually your best friend. The if f is None: # Wrapping libraries are quite capable but don't support charting. xlwt also as h f = pycel.Font() write(ws, 0, 3, "A bunch of long text to wrap", a mailing list that is active here: for attr, value in values: {"alignment":(("wrap", pycel.Alignment.WRAP_AT_RIGHT),)}) http://groups.google.com.au/group/python-excel f.__setattr__(attr, value) # Set column width FONT_FACTORY[font_key] = f Another good link is here: return f # (see pycel.BIFFRecords.ColInfoRecord for details, width in http://ntalikeris.blogspot.com/2007/10/create-excel-file-with-python -my-sort.html # 1/256th of zero character) write(ws, 0, 4, "A bunch of longer text not wrapped ") if __name__ == "__main__": This illustrates common usage for .xls generation, but also uses create_spreadsheet() ws.col(4).width = len("A bunch of longer text not wrapped ")*256 factories to limit object creation of styles (which can crash Excel) . It's meant to show example, but for more details, I recommend the # Freeze/split headers when scrolling sources I mention above. write(ws, 0, 5, "Header") ws.panes_frozen = True Please send comments/suggestions my way ws.horz_split_pos = 1 for row in range(1, 200): author: matthewharrison@gmail.com write(ws, row, 5, row) """ # Save the workbook #import pyExcelerator as pycel wb.save("out.xls") import xlwt as pycel def write(ws, row, col, data, style =None): # Excel has issues when creating too many styles/fonts, hence use """ # a factory to reuse instances (see FAQ#13 http://poi.apache.org/faq .html ) Write data to row, col of worksheet (ws) using the style STYLE_FACTORY = {} information. FONT_FACTORY = {} Again, I'm wrapping this because you'll have to do it if you def create_spreadsheet(): create large amounts of formatted entries in your spreadsheet # Create a workbook (else Excel, but probably not OOo will crash). wb = pycel.Workbook() """ if style: # Add a sheet s = get_style(style) ws = wb.add_sheet("Example Sheet") ws.write(row, col, data, s) else: # Tweak printer settings ws.write(row, col, data) # following makes a landscape layout on Letter paper # the width of the columns def get_style(style): ws.fit_num_pages = 1 """ ws.fit_height_to_pages = 0 Style is a dict maping key to values. ws.fit_width_to_pages = 1 Valid keys are: background, format, alignment, border # Set to Letter paper # See BiffRecords.SetupPageRecord for paper types/orientation The values for keys are lists of tuples containing (attribute, ws.paper_size_code = 1 value) pairs to set on model instances... # Set to landscape """ ws.portrait = 0 print "KEY", style style_key = tuple(style.items()) # Write some stuff using our helper function s = STYLE_FACTORY.get(style_key, None) if s is None: # Formatting - hint, look at Format code in OOo s = pycel.XFStyle() # format cells... Numbers tab for key, values in style.items(): # Write a percent if key == "background": write(ws, 0, 0, .495, {"format":"0%"}) p = pycel.Pattern() # Write a percent with negatives red for attr, value in values: write(ws, 1, 0, -.495, {"format":"0%;[RED]-0%"}) p.__setattr__(attr, value) # Dollar amounts s.pattern = p write(ws, 2, 0, 10.99, {"format":'$#,##0'}) elif key == "format": s.num_format_str = values # Font elif key == "alignment": # Size a = pycel.Alignment() write(ws, 0, 1, "Size 160(8pt)", {"font": (("height", 160),)}) for attr, value in values: write(ws, 1, 1, "Size 200(10pt)", {"font": (("height", 200),)}) a.__setattr__(attr, value) # Bold s.alignment = a matthewharrison@gmail.com write(ws, 2, 1, "Bold text", {"font": (("bold", True),)}) elif key == "border": b = pycel.Formatting.Borders() # Background color # See http://groups.google.com.au/group/python-excel/attach/93621400 bdddf464/palette_trial.xls?part=2 for attr, value in values: Creative Commons Attribution 3.0 License. b.__setattr__(attr, value) # for colour indices s.borders = b YELLOW = 5 elif key == "font": write(ws, 3, 1, "Yellow (5) Background ", f = get_font(values) {"background": (("pattern", pycel.Pattern.SOLID_PATTERN), s.font = f ( "pattern_fore_colour", YELLOW) )}) STYLE_FACTORY[style_key] = s return s