例如,下面的代码首先创建xlsx文件,然后将其作为下载流,但我想知道是否可以在创建时发送xlsx数据.例如,想象一下如果需要生成一个非常大的xlsx文件,用户必须等到它完成然后接收下载,我想要的是在用户浏览器中启动xlsx文件下载,然后发送在生成数据时.使用.csv文件似乎微不足道,但xlsx文件却不是这样.
try:
import cStringIO as StringIO
except ImportError:
import StringIO
from django.http import HttpResponse
from xlsxwriter.workbook import Workbook
def your_view(request):
# your view logic here
# create a workbook in memory
output = StringIO.StringIO()
book = Workbook(output)
sheet = book.add_worksheet('test')
sheet.write(0, 0, 'Hello, world!')
book.close()
# construct response
output.seek(0)
response = HttpResponse(output.read(), mimetype="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
response['Content-Disposition'] = "attachment; filename=test.xlsx"
return response
Run Code Online (Sandbox Code Playgroud) 输入: [{:a "ID1" :b 2} {:a "ID2" :b 4}]
我只想将所有键加起来:b
并生成以下内容:
结果: 6
我想过filter?
将所有数字拉入向量并将其全部加起来,但这似乎做了两次工作。我不能merge-with +
在这里使用,因为里面:a
有一个字符串。我是否使用reduce
带有可拉出适当键的函数的here ?
(reduce (fn [x] (+ (x :b))) 0 list-of-maps)
如果我可以保留具有更新值的地图结构会更好,({:a "ID1" :b 6})
但由于我真的不需要其他键,所以总和就可以了。
我在datomic-free中运行dev db
但是,我认为它会向数据库写一些东西但是当我做拉动时,它就不存在了.这是我的peer.clj
(ns dank.peer
(:require [datomic.api :as d :refer (q)]
[clojure.pprint :as pp]))
; Name the database as a uri
(def uri "datomic:mem://dank")
; Read the schema and seed data as strings
(def schema-tx (read-string (slurp "resources/dank/schema.edn")))
(def data-tx (read-string (slurp "resources/dank/seed-data.edn")))
; Initialize the db with above vars
(defn init-db
[]
(when (d/create-database uri)
(let
[conn (d/connect uri)]
@(d/transact conn schema-tx)
@(d/transact conn data-tx))))
(init-db)
(def conn (d/connect uri))
(def db (d/db conn))
(defn create
"Creates a new …
Run Code Online (Sandbox Code Playgroud) domain="www.google.com"
echo -e "\e[1;34m"$domain"\e[0m"
Run Code Online (Sandbox Code Playgroud)
我希望这会www.google.com
以绿色字母输出。
相反,我得到了
-e \e[1;34mwww.google.com\e[0m
我创建了一个简单的 chrome 扩展工具,用于在用户将浏览的页面上显示小文本消息(z-index 为 999999 的 div)。有时,div 仍然出现在现有页面的元素下方,更糟糕的是,div 的内容会发生变化,因为页面已经有了自己的 CSS 规则。
挑战在于如何确保我的文本消息显示在所有元素的顶部(适用于任何站点),并且看起来一致且不受现有 CSS 规则的影响。
iframe 能解决这个问题吗?但是,即使使用 iframe,它仍然需要出现在所有元素的顶部,并且似乎 z-index 并不总是有效。
我正在尝试在 AWS 上的 dynamodb 上部署一个 datomic 应用程序,但是当我检查 ec2 上的对等实例时,我注意到它由于以下堆栈跟踪而无法启动,这对于确定失败的原因没有帮助。
un 01, 2016 6:17:50 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class myapp.listener
java.lang.RuntimeException: could not start [#'myapp.db.core/conn] due to
at mount.core$up$fn__390.invoke(core.cljc:92)
at mount.core$up.invokeStatic(core.cljc:92)
at mount.core$up.invoke(core.cljc:90)
at mount.core$bring.invokeStatic(core.cljc:206)
at mount.core$bring.invoke(core.cljc:198)
at mount.core$start.invokeStatic(core.cljc:246)
at mount.core$start.doInvoke(core.cljc:242)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at myapp.handler$init.invokeStatic(handler.clj:27)
at myapp.handler$init.invoke(handler.clj:21)
at clojure.lang.Var.invoke(Var.java:375)
at myapp.listener$_contextInitialized.invokeStatic(listener.clj:1)
at myapp.listener$_contextInitialized.invoke(listener.clj:1)
at myapp.listener.contextInitialized(Unknown Source)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1091)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1980) …
Run Code Online (Sandbox Code Playgroud) 因此,在用户创建帐户之前,我想保存他们的信用卡以收取 30 天试用期的订阅费用,并且如果用户需要,能够立即向卡收取订阅费用。
所以我的逻辑是
1)创建客户
2) 添加客户的付款详细信息
3) 创建 30 天试用期的订阅
4) 在用户升级操作时激活订阅
我不清楚4)如何可能。我在 3) 得到消息,30 天后,他们就开始订阅了。但是,如果客户想在试用期结束前立即开始使用完整版本,我该如何收取订阅费用呢?
const stripe = require('stripe')('sk_test_asdfasdf');
(async () => {
// Create a Customer:
stripe.customers.create({
email: 'jenny.rosen@example.com',
payment_method: 'pm_1FWS6ZClCIKljWvsVCvkdyWg',
invoice_settings: {
default_payment_method: 'pm_1FWS6ZClCIKljWvsVCvkdyWg',
},
}, function(err, customer) {
// asynchronously called
});
//create subscription
stripe.subscriptions.create({
customer: 'cus_4fdAW5ftNQow1a',
items: [
{
plan: 'plan_CBXbz9i7AIOTzr',
},
],
expand: ['latest_invoice.payment_intent'],
}, function(err, subscription) {
// asynchronously called
}
);
})();
Run Code Online (Sandbox Code Playgroud) def log():
with open("log.txt", 'a') as f:
print ".log.txt"
f.write(msg.encode('utf-8') +"\n")
Run Code Online (Sandbox Code Playgroud)
我多次调用log()但是没有在新行上写每个msg,我也不知道为什么.我尝试在最后添加f.close(),但这也不起作用.超级沮丧!
所以我在我的asp.net项目上安装了一个Nuget包,该包已经过时了,没有帮助。我需要修改此nuget软件包的源代码,以便手动放入补丁。我还需要设置断点和调试,但是VS 2015不允许我介入任何属于Nuget包的更深层的代码。
Windows 7计算机上的nuget软件包源文件在哪里?是否有更好的修补旧的nuget软件包的方法?