我正在使用reportlab创建一个表,我想在下表中对齐单个单元格(右侧):
我想对齐包含"职业"对了
这是我的代码:
studentProfileData = [
['Application Form No', ''],
['Name', userData['studentDetails']["firstName"] + " " +userData['studentDetails']["lastName"]],
['Course opted for', userData['courseDetails']["courseOptedFor"]],
['Specific Course Name', courseMapping["Name"]],
['Category', userData['studentDetails']['caste']],
['Religion', userData['studentDetails']['religion']],
['Fathers'+ "'" +'s Name', userData['studentDetails']['religion']],
['Occupation', userData['studentDetails']['fOccupation']],
['Phone No', ""],
['Term', ""]
]
colwidths = [3 * inch, 1.5 * inch, inch]
# Two rows with variable height
rowheights = [.5*inch] * len(studentProfileData)
studentProfile = Table(studentProfileData, colwidths, rowheights, hAlign='LEFT')
studentProfile.setStyle(TableStyle([
('ALIGN', (0, 0), (0, -1), "LEFT"),
('FONTSIZE', (0,0), (-1, -1), 13),
]))
parts = [ page1Head, studentProfile]
答案 0 :(得分:1)
为了在Reportlab (0,7)
中对齐单个单元格,我们需要将(0,7)
更改为以下内容:
Occupation
这是有效的,因为我们现在告诉Paragraph
和String
之间区域中的单元格应该正确对齐,因为该区域中唯一的单元格是包含Paragraph
仅包含该文本的单元格是对齐的。
另一种方法是在表格中使用pageTextStyleCenter = ParagraphStyle(name="left", alignment=TA_CENTER, fontSize=13, leading=10)
[ Paragraph("Occupation", pageTextStyleCenter) , userData['studentDetails'].get('fOccupation', "-")]
而不是from this import s, d
from string import translate, maketrans
from flask import Flask
from flask.ext.cache import Cache
app = Flask(__name__)
cache = Cache(app, config={'CACHE_TYPE': 'memcached',
'CACHE_MEMCACHED_SERVERS' : "My endpoint",
'CACHE_KEY_PREFIX' : "optimization"})
#cache = Cache(app, config={'CACHE_TYPE': 'filesystem', 'CACHE_DIR': '/tmp'})
@cache.cached(timeout=10, key_prefix="current_time")
def get_current_time():
return time.ctime()
def random_zen_quote():
"""Pick a random quote from the Zen of Python"""
transtable = maketrans("".join(d.keys()), "".join(d.values()))
return random.choice(translate(s, transtable).split("\n")[2:])
@app.route("/")
def zen():
return """
<ul>
<li><strong>It is cached:</strong> {cached}</li>
<li><strong>It is not cached:</strong> {not_cached}</li>
</ul>
""".format(
cached=get_current_time(),
not_cached=random_zen_quote()
)
if __name__ == "__main__":
app.run(debug=True, port=5000, host='0.0.0.0')
,在这种情况下,我们可以与Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/projects/mv2/test.py", line 34, in zen
cached=get_current_time(),
File "/usr/local/lib/python2.7/site-packages/Flask_Cache-0.13.1-py2.7.egg/flask_cache/__init__.py", line 289, in decorated_function
rv = self.cache.get(cache_key)
File "/usr/local/lib/python2.7/site-packages/werkzeug/contrib/cache.py", line 406, in get
return self._client.get(key)
对齐,因为它将填充整个宽度细胞。
段落示例
<script>
var playerData = {!! $player_data !!};
</script>