[英]How do I know which cell is highlighted in jexcell javascript library?
我想合并标有 jexcel 的单元格。 我不知道该怎么做。 更具体地说,我想将单元格合并到动态 state 中,并将它们写入 MySQL 中的合并单元格中。 怎么做
<div id="example"></div>
<script>
var data = [
['', 'Ford', 'Tesla', 'Toyota', 'Honda'],
['2017', 10, 11, 12, 13],
['2018', 20, 11, 14, 13],
['2019', 30, 15, 12, 13]
];
var container = document.getElementById('example');
var hot = new Handsontable(container, {
data: data,
rowHeaders: true,
colHeaders: true,
filters: true,
dropdownMenu: true,
contextMenu: true
});
</script>
您的问题不清楚,但我会尽力回答。
如果我忽略您提供的示例并专注于 jExcel,我们可以使用setMerge
合并单元格,为此我们需要知道:
我们可以从以下位置提取此信息:
$("#spreadsheet").jexcel("getSelectedRows", true);
$("#spreadsheet").jexcel("getSelectedColumns", true);
理论上,仅此一项就应该起作用,但是当 jExcel 失去焦点时(即当用户单击按钮时),它会取消选择单元格,这就是为什么我使用工作方法将单元格的选择存储在 object 中,然后使用 object 来合并单元格。
<div id="spreadsheet"></div>
<br>
<input id="myB" type="button" value="Merge Selected" />
var mySlection = {};
var options = {
minDimensions: [10, 10],
onselection: storeSelection
};
$(document).ready(function() {
var mySpreadsheet = $("#spreadsheet").jexcel(options);
$("#myB").click(function() {
//Merge Cells using the stored selection
$("#spreadsheet").jexcel("setMerge", mySlection.firstcell, mySlection.colspan, mySlection.rowspan)
/*
you may now store the following values to your MySQL
mySlection.firstcell
mySlection.colspan
mySlection.rowspan
*/
});
});
function storeSelection() {
var sRows = $("#spreadsheet").jexcel("getSelectedRows", true);
var sCols = $("#spreadsheet").jexcel("getSelectedColumns", true);
mySlection.firstcell = [sCols[0], sRows[0]];
mySlection.colspan = sCols.length;
mySlection.rowspan = sRows.length;
}
要求: jQuery、jExcel 和 jSuites v3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.