python-docx table styles not accepting styles - datatable

I am trying to make a table in Word with python-docx, but after creating the table and saving the file, the table doesn't have any lines / separators. So I tried to use the table.style option, but I just can't get any style to work, except Normal Table (which is the default).
This is the code I use to create the table:
import docx
file = docx.Document()
table = file.add_table(6, 4)
fRow = table.rows[0]
fRow[0].text = "some headline"
...
table.style = "<stylename here>"
file.save("test.docx")
All of the styles I tried are from this website:
https://python-docx.readthedocs.io/en/latest/user/styles-understanding.html#built-in-styles
I am using Python 3.10.0b4 on Windows 11.

This is the code I used to accomplish this:
table = document.add_table(rows=1, cols=2, style='Table Grid')
for your line, believe it would be
table = file.add_table(6, 4, style='Table Grid')

Related

Use an Ironpython script to filter and pass filter selections between tables

I have two tables in the analysis. I am using the script below to be able to filter table A and pass those filter selections to the matching filter in table B. Table A and B are visualized in a bar chart. I am triggering the code when the value of a document property changes, following instructions here.
I am running into two problems.
1) After the script runs, clicking Reset All Filters results in only table A being displayed in the visualization. Clicking Reset All Filters again fixes the issue.
2)When I add a second filter (commented out in the code below), making a selection in the Type_A or or Type_B filter wipes out the type B data from the visualization. I think the problem is in how IncludeAllValues is being handled, but I don't know how to fix it. Any help will be appreciated.
from Spotfire.Dxp.Application.Filters import *
from Spotfire.Dxp.Application.Visuals import VisualContent
from System import Guid
#Get the active page and filterPanel
page = Application.Document.ActivePageReference
filterPanel = page.FilterPanel
theFilterA = filterPanel.TableGroups[0].GetFilter("Type_A")
lbFilterA = theFilterA.FilterReference.As[ListBoxFilter]()
theFilter2A = filterPanel.TableGroups[1].GetFilter("Type_A")
lb2FilterA = theFilter2A.FilterReference.As[ListBoxFilter]()
lb2FilterA.IncludeAllValues = False
lb2FilterA.SetSelection(lbFilterA.SelectedValues)
#########################Type_B###########################
# theFilterB = filterPanel.TableGroups[0].GetFilter("Type_B")
# lbFilterB = theFilterB.FilterReference.As[ListBoxFilter]()
# theFilter2B = filterPanel.TableGroups[1].GetFilter("Type_B")
# lb2FilterB = theFilter2B.FilterReference.As[ListBoxFilter]()
# lb2FilterB.IncludeAllValues = False
# lb2FilterB.SetSelection(lbFilterB.SelectedValues)

Trouble with Expression in SSIS Derived Column Transform Editor [duplicate]

This question already has answers here:
SSIS How to get part of a string by separator using Derived Column
(3 answers)
Closed 7 years ago.
I need to split up one column into two columns. The data in the column is currently split by a dash (see below) and has parenthesis between the text.
Example of column: (Data1) - (Data2)
I have a Query that I used against the database that Works, but I am having trouble creating this Expression in SSIS.
Here are the queries I have used in SSMS that generate the New columns without the dash and parenthesis:
To get the data on the left side of the column into a New column:
SELECT SUBSTRING(REPLACE(REPLACE(REPLACE(COLUMN_NAME,'(',''),')',''),' ',''),0,CHARINDEX('-',
REPLACE(REPLACE(REPLACE(COLUMN_NAME,'(',''),')',''),' ',''))) AS NEW_COLUMN_NAME
FROM TABLE
To get the data on the right of the column into a New column:
SELECT SUBSTRING(REPLACE(REPLACE(REPLACE(COLUMN_NAME,'(',''),')',''),' ',''),CHARINDEX('-',
REPLACE(REPLACE(REPLACE(STREKNING_NAVN,'(',''),')',''),' ',''))+1,LEN(REPLACE(REPLACE(REPLACE(COLUMN_NAME,'(',''),')',''),' ',''))) AS NEW_COLUMN_NAME
FROM TABLE
Can anyone offer any tips?
Thank you in advance.
I prefer to solve string manipulation problems with a script task because the code is much more robust and clean than anything that can be done in SQL or SSIS expressions. So it would go something like this:
Add a Script Task
Add two string columns (i.e. "Column1" and "Column2")
Do the following in a script task (assuming input column is named "col":
using System.Text.RegularExpressions;
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
string[] columns = Row.col.ToString().Split('-');
Regex reg = new Regex(#"[\(\)]");
Row.Column1 = reg.Replace(columns[0], "");
Row.Column2 = reg.Replace(columns[1], "");
}
So the split function converts the string to an array and we can use regex to remove the parentheses.

How to cache and persist the temporary tables in Spark SQL?

I have working code for reading a text file and using as a registered temporary table in memory. I would like to load a set of these tables using a script or a module import and then query them interactively. If if put this code into a script and a function, which is the object I should return? The sc context? The table? The HadoopRDD?
file = "/file.tsv"
lines = sc.textFile(file)
parts = lines.map(lambda l: l.split("\t")).filter(lambda line:len(line)==7)
active_sessions = parts.map(lambda p: Row(
session=p[0]
, user_id=p[1]
, created=p[2]
, updated=p[3]
, id=p[4]
, deleted=p[5]
, resource_id=p[6]))
schemaTable = sqlContext.inferSchema(active_sessions)
schemaTable.registerTempTable("active_sessions")
sqlContext.cacheTable("active_sessions")
I had the same issue and ended up returning:
return sqlContext.table("active_sessions")
I had registered it as a table rather than a temptable though, but it works with temptables as well.

Getting value of database field in Crystal Reports

Currently I'm working on legacy application, that uses crystal report engine. I have to get value of database fields programmatically. As I've assumed, I need proper event for getting next code to work:
Report.Database.Tables(1).Fields(1).Value
But the value is always empty in DownloadStarted/Finished event handlers. What I'm doing wrong and is it at least possible?
I think that if you want to get value of your table fields in program the best way is that you get the field name from report and then connect to your table directly and use report field names as the table columns name
i do it in c# i hope it can help you in vb6 too:
string name = report2.Database.Tables[1].Fields[1].Name;
string[] names = name.Split('.');
and then add your database to your program and use names like this:
DataTable dt = new DataTable();
string[] value = dt.Columns[names[1]];
if you just need your tables values, you can use my last answer, but if you need value of database fields in crystal report, i mean something like formula field ,this code can help you:
CRAXDRT.FormulaFieldDefinitions definitions = report2.FormulaFields;
string formulaText = "IF " + report2.Database.Tables[1].Fields[3].Name
+ " > 10 THEN" + report2.Database.Tables[1].Fields[2].Name;
definitions.Add("Test", formulaText);
report2.Sections[1].AddFieldObject(definitions[1], 0, 0);

how to export and import BLOB data type in oracle

how to export and import BLOB data type in oracle using any tool. i want to give that as release
Answering since it has a decent view count even with it being 5 year old question..
Since this question was asked 5 years ago there's a new tool named SQLcl ( http://www.oracle.com/technetwork/developer-tools/sqlcl/overview/index.html)
We factored out the scripting engine out of SQLDEV into cmd line. SQLDev and this are based on java which allows usage of nashorn/javascript engine for client scripting. Here's a short example that is a select of 3 columns. ID just the table PK , name the name of the file to create, and content the BLOB to extract from the db.
The script command triggers this scripting. I placed this code below into a file named blob2file.sql
All this adds up to zero plsql, zero directories instead just some sql scripts with javascript mixed in.
script
// issue the sql
// bind if needed but not in this case
var binds = {}
var ret = util.executeReturnList('select id,name,content from images',binds);
// loop the results
for (i = 0; i < ret.length; i++) {
// debug messages
ctx.write( ret[i].ID + "\t" + ret[i].NAME+ "\n");
// get the blob stream
var blobStream = ret[i].CONTENT.getBinaryStream(1);
// get the path/file handle to write to
// replace as need to write file to another location
var path = java.nio.file.FileSystems.getDefault().getPath(ret[i].NAME);
// dump the file stream to the file
java.nio.file.Files.copy(blobStream,path);
}
/
The result is my table emptied into files ( I only had 1 row ). Just run as any plain sql script.
SQL> #blob2file.sql
1 eclipse.png
blob2file.sql eclipse.png
SQL>

Resources