vsto - 如何通过文本字段在 Excel VSTO 加载项中获取用户的数据范围输入?
问题描述
我想在 Excel 加载项上创建一个条形图,但我想在文本字段中从用户那里获取数据范围,如何使用该值并将其分配给 dataRange 变量?这是我的代码:在 home.html 中,
<input type="text" id="chart-range" class="right" />
在 Home.js 中:
$("#chart-range").change(function ()
var input = document.getElementById("chart-range");
var value = input.options[input.selectedIndex].value;
createBarChart();
})
})
function createBarChart() {
Excel.run(function (context) {
const sheet = context.workbook.worksheets.getItem("Sheet1");
const salesTable = sheet.tables.getItem("Table1");
const dataRange = salesTable.getDataBodyRange();
let chart = sheet.charts.add("ColumnClustered", dataRange, "Auto");
chart.setPosition("A9", "F20");
chart.title.text = "Farm Sales Bar chart";
chart.legend.position = "Right";
chart.legend.format.fill.setSolidColor("white");
chart.dataLabels.format.font.size = 15;
chart.dataLabels.format.font.color = "black";
let points = chart.series.getItemAt(0).points;
points.getItemAt(0).format.fill.setSolidColor("pink");
points.getItemAt(1).format.fill.setSolidColor("indigo");
return context.sync();
})
.catch(function (error) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});
}
解决方案
推荐阅读
- arrays - 在 mongodb 的嵌套数组中的过滤器后包含数组索引
- html - 为什么悬停后看不到特定部分?
- sql-server - 如何在 SQL Server 2008 中获取一行中的计数
- dax - PowerPivot DAX 日期查找
- python - 在文本文件中搜索并保存在 Excel 中
- css - 用另一种字体设计数字
- regex - 正则表达式在第一次出现字符之前获取所有内容
- python - 如何使用 Python 在 Outlook 中提取电子邮件正文的一小部分?
- docker - 有没有办法找出用于构建映像的 docker 版本?
- android - 阅读收件箱中的所有短信或将其发送到 React NATIVE 中的服务器