我正在用apache-poi生成一个docx文件.在wordfile中,我添加了表,其列的宽度我希望看到固定.
目前,我使用此处描述的技术:http://apache-poi.1045710.n5.nabble.com/Is-there-a-way-set-set-the-width-of-a-column-in-XWPFTableCell -td5711491.html
基本上,这需要设置
cell.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(cols[j]));
Run Code Online (Sandbox Code Playgroud)
在该列的每个单元格上.
问题是,当文件在MS Word中完美打开时,open office会以不同的方式将我设置的值解释为列宽.虽然MS Word显然假设20个点为单位,但开放办公室似乎使用点代替,因此当我在OO中打开生成的文档时,所有列都宽20倍.
通常当我在生成的输出中看到一些奇怪的东西时,我解压缩docx文件,查看值应该是什么并更改我的代码.但是开放式办公室似乎无法保存到docx,因此我无法更改OO中的值将其保存回来并查看Word是否仍然正确解释文档以便找到跨应用程序解决方案.
知道如何设置表格列的宽度,以便OO和MS Wordt同样解释它吗?
我正在用 Java 构建一个简单的命令行应用程序,它可以登录我的电子邮件箱 (IMAP) 并下载所有附件。我使用了基本身份验证,但 Microsoft 正在禁用它,因此我尝试将我的应用程序转换为使用 OAuth。
在阅读了不同的 OAuth 流程后,似乎对于我的简单独立命令行应用程序来说,简单地硬编码密码没有问题,资源所有者密码凭据 Grand(如此处所述)将是最佳(或良好)选择。我进一步根据此来源的说明,其中描述了如何使用最新版本的 Javamail 启用 OAuth。
将它们放在一起似乎有点困难,而且我不断收到 AUTHENTICATE Failed 错误。
那么,我尝试了什么?我首先按如下方式检索我的授权令牌:
public String getAuthToken() {
try {
CloseableHttpClient client = HttpClients.createDefault();
HttpPost loginPost = new HttpPost("https://login.microsoftonline.com/organizations/oauth2/v2.0/token");
String clientId = "some client UUID";
String scopes = "email openid IMAP.AccessAsUser.All offline_access";
String client_secret = "My client secret, not base64 encoded";
String username = "my emailadress";
String password = "my password, not base64 encoded";
String encodedBody = "client_id=" + clientId …Run Code Online (Sandbox Code Playgroud) 我试图将Map转换为另一个Map,其中新键只是原始键toString().使用流API我按如下方式执行此操作:
mapMap.entrySet().stream().collect(Collectors.toMap(
(Map.Entry entry) -> entry.getKey().toString(),
(Map.Entry entry) -> entry.getValue()
));
Run Code Online (Sandbox Code Playgroud)
问题是这不保留内部Map类型.如果原始地图恰好是HashMap,我不介意返回TreeMap,但另一种方法是有问题的,因为删除了元素的排序.我一直在使用上述代码的变体来搞定这个,但我似乎并没有走得太远.现在,我写的没有溪流,如下:
TreeMap<String, Integer> stringMap = new TreeMap<>();
for (OriginalType t: originalMap.keySet()) {
stringMap.put(t.toString(), originalMap.get(t));
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以让我朝着正确的方向用流来做这件事吗?谢谢
我在 Amazon RDS 生产数据库上有一个相对较大的表(在 2M 条记录范围内)。我希望对多个字段进行分组,包括表中日期的月份(server_time)。为了加快速度,我在 master 数据库上创建了一个索引,如下所示:
create index on build_requests(group_id, artifact_id, account_id, number_of_interfaces, date_trunc('month', server_build_time));
Run Code Online (Sandbox Code Playgroud)
然后,正如您所期望的,对数据进行分组的查询使用主服务器上的索引:
GroupAggregate (cost=0.55..311308.09 rows=1633231 width=85)
Group Key: group_id, artifact_id, account_id, number_of_interfaces, date_trunc('month'::text, server_build_time)
-> Index Scan using build_requests_group_id_artifact_id_account_id_number_of_in_idx on build_requests (cost=0.55..262417.68 rows=1898335 width=85)
Run Code Online (Sandbox Code Playgroud)
然而,等待一个多小时后,只读副本仍然没有使用索引:
GroupAggregate (cost=434678.88..488313.41 rows=1633179 width=85)
Group Key: group_id, artifact_id, account_id, number_of_interfaces, (date_trunc('month'::text, server_build_time))
-> Sort (cost=434678.88..439424.56 rows=1898274 width=85)
Sort Key: group_id, artifact_id, account_id, number_of_interfaces, (date_trunc('month'::text, server_build_time))
-> Seq Scan on build_requests (cost=0.00..55053.43 rows=1898274 width=85)
Run Code Online (Sandbox Code Playgroud)
使用 pgadmin 登录只读副本,我发现索引仍然存在。这是一个问题,因为只读副本上的查询速度较慢(5 分钟 vs 3 …
apache-poi ×1
imap ×1
jakarta-mail ×1
java ×1
java-8 ×1
java-stream ×1
ms-word ×1
oauth ×1
office365 ×1
postgresql ×1
sql ×1
xwpf ×1