mengshukeji 5 years ago
parent
commit
4acc36d385
  1. 35
      docs/zh/guide/api.md
  2. 1
      src/config.js
  3. 5
      src/controllers/constant.js
  4. 8
      src/controllers/keyboard.js
  5. 38
      src/controllers/selection.js
  6. 3
      src/core.js
  7. 456
      src/global/api.js
  8. 313
      src/global/getRowlen.js
  9. 5
      src/global/setdata.js
  10. 7
      src/global/validate.js
  11. 4
      src/index.html
  12. 1
      src/store/index.js
  13. 2
      src/utils/util.js

35
docs/zh/guide/api.md

@ -216,7 +216,6 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
------------
### exitEditMode([,setting])
- **参数**
@ -1700,8 +1699,6 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
### getAllSheets()
[todo]
- **说明**
返回所有工作表配置,格式同工作表配置,得到的结果可用于表格初始化时作为options.data使用。
@ -1971,9 +1968,6 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
### setSheetOrder(orderList [,setting])
[todo]
- **参数**
- {Array} [orderList]: 工作表顺序,设置工作表的index和order来指定位置,如:
@ -2094,9 +2088,6 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
### refresh([setting])
[todo]
- **参数**
- {PlainObject} [setting]: 可选参数
@ -2110,14 +2101,11 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
### scroll([setting])
[todo]
- **参数**
- {PlainObject} [setting]: 可选参数
+ {Number} [scrollWidth]:横向滚动值。默认为当前横向滚动位置。
+ {Number} [scrollHeight]:纵向滚动值。默认为当前纵向滚动位置。
+ {Number} [scrollLeft]:横向滚动值。默认为当前横向滚动位置。
+ {Number} [scrollTop]:纵向滚动值。默认为当前纵向滚动位置。
+ {Number} [targetRow]:纵向滚动到指定的行号。默认为当前纵向滚动位置。
+ {Number} [targetColumn]:横向滚动到指定的列号。默认为当前横向滚动位置。
+ {Function} [success]: 表格刷新成功后的回调函数
@ -2156,27 +2144,22 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
### getScreenshot([setting])
[todo]
- **参数**
- {PlainObject} [setting]: 可选参数
+ {Array | Object | String} [range]: 选区范围,支持选区的格式为`"A1:B2"`、`"sheetName!A1:B2"`或者`{row:[0,1],column:[0,1]}`,只能为单个选区;默认为当前选区
+ {Number} [order]: 工作表下标;默认值为当前工作表下标
+ {Object | String} [range]: 选区范围,支持选区的格式为`"A1:B2"`、`"sheetName!A1:B2"`或者`{row:[0,1],column:[0,1]}`,只能为单个选区;默认为当前选区
- **说明**
返回指定选区截图后生成的base64格式的图片
返回当前表格指定选区截图后生成的base64格式的图片
------------
### setWorkbookName(name [,setting])
[todo]
- **参数**
- {Number} [name]: 工作簿名称
- {String} [name]: 工作簿名称
- {PlainObject} [setting]: 可选参数
+ {Function} [success]: 操作结束的回调函数
@ -2188,9 +2171,6 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
### undo([setting])
[todo]
- **参数**
- {PlainObject} [setting]: 可选参数
@ -2204,9 +2184,6 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
### redo([setting])
[todo]
- **参数**
- {PlainObject} [setting]: 可选参数
@ -2392,8 +2369,6 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
### transToData(celldata [,setting])<div id='transToData'></div>
[todo]
- **参数**
- {Array} [celldata]: data数据

1
src/config.js

@ -56,4 +56,5 @@ export default {
columeHeaderHeight: 20,
defaultColWidth:73,
defaultRowHeight:19,
defaultFontSize:10,
}

5
src/controllers/constant.js

@ -530,9 +530,6 @@ function rightclickHTML(){
<button id="luckysheet-matrix-delerpt-column" class="btn btn-primary luckysheet-mousedown-cancel" style="margin-left:5px;padding:2px 3px;line-height:12px;font-size:12px;">${rightclick.byCol}</button>
</div>
</div>
<div class="luckysheet-cols-menuitem luckysheet-mousedown-cancel">
<div class="luckysheet-cols-menuitem-content luckysheet-mousedown-cancel">${rightclick.generateNewMatrix}</div>
</div>
</div>`;
}
@ -1548,7 +1545,7 @@ const luckysheetdefaultstyle = {
}
const luckysheetdefaultFont = function(){
return 'normal normal normal 10pt '+ locale().fontarray[0] +', "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "Heiti SC", "WenQuanYi Micro Hei", sans-serif';
return 'normal normal normal '+ Store.defaultFontSize +'pt '+ locale().fontarray[0] +', "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "Heiti SC", "WenQuanYi Micro Hei", sans-serif';
}
const luckysheet_CFiconsImg = new Image();

8
src/controllers/keyboard.js

@ -269,10 +269,6 @@ export function keyboardInitial(){
$("#luckysheet-input-box").click(function () {
formula.rangeHightlightselected($("#luckysheet-rich-text-editor"));
}).add("#" + Store.container).on("keydown", function (event) {
if ($("#luckysheet-modal-dialog-mask").is(":visible") || $(event.target).hasClass("luckysheet-mousedown-cancel") || $(event.target).hasClass("formulaInputFocus")) {
return;
}
let ctrlKey = event.ctrlKey;
let altKey = event.altKey;
let shiftKey = event.shiftKey;
@ -322,6 +318,10 @@ export function keyboardInitial(){
return;
}
if ($("#luckysheet-modal-dialog-mask").is(":visible") || $(event.target).hasClass("luckysheet-mousedown-cancel") || $(event.target).hasClass("formulaInputFocus")) {
return;
}
let $inputbox = $("#luckysheet-input-box");

38
src/controllers/selection.js

@ -8,7 +8,7 @@ import formula from '../global/formula';
import { getBorderInfoCompute } from '../global/border';
import { getdatabyselection, getcellvalue, datagridgrowth } from '../global/getdata';
import { rowlenByRange } from '../global/getRowlen';
import { isEditMode, hasPartMC } from '../global/validate';
import { isEditMode, hasPartMC, isRealNum } from '../global/validate';
import { jfrefreshgrid, jfrefreshgrid_pastcut } from '../global/refresh';
import { genarate, update } from '../global/format';
import { getSheetIndex } from '../methods/get';
@ -801,14 +801,36 @@ const selection = {
for (let r = 0; r < rlen; r++) {
let x = [].concat(d[r + curR]);
for (let c = 0; c < clen; c++) {
let cell = {};
let mask = genarate(dataChe[r][c]);
cell.v = mask[2];
cell.ct = mask[1];
cell.m = mask[0];
let value = dataChe[r][c];
if(isRealNum(value)){
value = parseFloat(value);
}
let originCell = x[c + curC];
if(originCell instanceof Object){
originCell.v = value;
if(originCell.ct!=null && originCell.ct.fa!=null){
originCell.m = update(originCell["ct"]["fa"], value);
}
else{
originCell.m = value;
}
if(originCell.f!=null && originCell.f.length>0){
originCell.f = "";
formula.delFunctionGroup(r + curR,c + curC,Store.currentSheetIndex);
}
}
else{
let cell = {};
let mask = genarate(value);
cell.v = mask[2];
cell.ct = mask[1];
cell.m = mask[0];
x[c + curC] = cell;
x[c + curC] = cell;
}
}
d[r + curR] = x;
}

3
src/core.js

@ -62,6 +62,7 @@ luckysheet.create = function (setting) {
Store.lang = extendsetting.lang; //language
Store.allowEdit = extendsetting.allowEdit;
Store.fontList = extendsetting.fontList;
Store.defaultFontSize = extendsetting.defaultFontSize;
server.gridKey = extendsetting.gridKey;
server.loadUrl = extendsetting.loadUrl;
server.updateUrl = extendsetting.updateUrl;
@ -104,7 +105,9 @@ luckysheet.create = function (setting) {
luckysheetConfigsetting.plugins = extendsetting.plugins;
luckysheetConfigsetting.rowHeaderWidth = extendsetting.rowHeaderWidth;
Store.rowHeaderWidth = extendsetting.rowHeaderWidth;
luckysheetConfigsetting.columeHeaderHeight = extendsetting.columeHeaderHeight;
Store.columeHeaderHeight = extendsetting.columeHeaderHeight;
luckysheetConfigsetting.defaultColWidth = extendsetting.defaultColWidth;
luckysheetConfigsetting.defaultRowHeight = extendsetting.defaultRowHeight;

456
src/global/api.js

@ -1,5 +1,5 @@
import Store from "../store";
import { replaceHtml, getObjType, chatatABC } from "../utils/util";
import { replaceHtml, getObjType, chatatABC, luckysheetactiveCell } from "../utils/util";
import { getSheetIndex, getluckysheet_select_save, getluckysheetfile } from "../methods/get";
import locale from "../locale/locale";
@ -20,6 +20,7 @@ import { luckysheetDeleteCell, luckysheetextendtable, luckysheetdeletetable } fr
import { isRealNull, valueIsError, isRealNum, isEditMode, hasPartMC } from "./validate";
import { isdatetime, diff } from "./datecontroll";
import { getBorderInfoCompute } from './border';
import { luckysheetDrawMain } from './draw';
import server from "../controllers/server";
import menuButton from '../controllers/menuButton';
@ -31,8 +32,9 @@ import sheetmanage from '../controllers/sheetmanage';
import conditionformat from '../controllers/conditionformat';
import { luckysheet_searcharray } from "../controllers/sheetSearch";
import { selectHightlightShow, selectIsOverlap } from '../controllers/select';
import { sheetHTML } from '../controllers/constant';
import { sheetHTML, luckysheetdefaultstyle } from '../controllers/constant';
import { createFilterOptions } from '../controllers/filter';
import controlHistory from '../controllers/controlHistory';
const IDCardReg = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i;
@ -433,6 +435,21 @@ export function replace(content, replaceContent, options = {}) {
return matchCells;
}
/**
* 手动触发退出编辑模式
* @param {Object} options 可选参数
* @param {Function} options.success 操作结束的回调函数
*/
export function exitEditMode(options = {}){
formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]);
if (options.success && typeof options.success === 'function') {
options.success();
}
}
/**
* 冻结首行
* 若设置冻结的sheet不是当前sheet页只设置参数不渲染
@ -4647,9 +4664,221 @@ export function setSheetMove(type, options = {}) {
}
/**
* 重新排序所有工作表的位置指定工作表顺序的数组
* @param {Array} orderList 工作表顺序设置工作表的index和order来指定位置
* @param {Object} options 可选参数
* @param {Function} options.success 操作结束的回调函数
*/
export function setSheetOrder(orderList, options = {}) {
if(orderList == null || orderList.length == 0){
return tooltip.info("Type orderList not available", "");
}
let orderListMap = {};
orderList.forEach((item) => {
orderListMap[item.index.toString()] = item.order;
})
Store.luckysheetfile.sort((x, y) => {
let order_x = orderListMap[x.index.toString()];
let order_y = orderListMap[y.index.toString()];
if(order_x != null && order_y != null){
return order_x - order_y;
}
else if(order_x != null){
return -1;
}
else if(order_y != null){
return 1;
}
else{
return 1;
}
})
let orders = {};
Store.luckysheetfile.forEach((item, i, arr) => {
arr[i].order = i;
orders[item.index.toString()] = i;
if(i > 0){
let preIndex = arr[i - 1].index;
$("#luckysheet-sheets-item" + item.index).insertAfter($("#luckysheet-sheets-item" + preIndex));
}
})
server.saveParam("shr", null, orders);
let {
success
} = {...options}
if (success && typeof success === 'function') {
success();
}
}
/**
* 显示指定下标工作表的网格线返回操作的工作表对象
* @param {Object} options 可选参数
* @param {Number} options.order 需要显示网格线的工作表下标默认值为当前工作表下标
* @param {Function} options.success 操作结束的回调函数
*/
export function showGridLines(options = {}){
let {
order = getSheetIndex(Store.currentSheetIndex),
success
} = {...options}
let file = Store.luckysheetfile[order];
if(file == null){
return tooltip.info("The order parameter is invalid.", "");
}
file.showGridLines = true;
if(file.index == Store.currentSheetIndex){
Store.showGridLines = true;
setTimeout(function () {
luckysheetrefreshgrid();
}, 1);
}
setTimeout(() => {
if (success && typeof success === 'function') {
success();
}
}, 1);
return file;
}
/**
* 隐藏指定下标工作表的网格线返回操作的工作表对象
* @param {Object} options 可选参数
* @param {Number} options.order 需要显示网格线的工作表下标默认值为当前工作表下标
* @param {Function} options.success 操作结束的回调函数
*/
export function hideGridLines(options = {}){
let {
order = getSheetIndex(Store.currentSheetIndex),
success
} = {...options}
let file = Store.luckysheetfile[order];
if(file == null){
return tooltip.info("The order parameter is invalid.", "");
}
file.showGridLines = false;
if(file.index == Store.currentSheetIndex){
Store.showGridLines = false;
setTimeout(function () {
luckysheetrefreshgrid();
}, 1);
}
setTimeout(() => {
if (success && typeof success === 'function') {
success();
}
}, 1);
return file;
}
/**
* 刷新canvas
* @param {Object} options 可选参数
* @param {Function} options.success 操作结束的回调函数
*/
export function refresh(options = {}) {
luckysheetrefreshgrid();
let {
success
} = {...options}
if (success && typeof success === 'function') {
success();
}
}
/**
* 滚动当前工作表位置
* @param {Object} options 可选参数
* @param {Number} options.scrollLeft 横向滚动值
* @param {Number} options.scrollTop 纵向滚动值
* @param {Number} options.targetRow 纵向滚动到指定的行号
* @param {Number} options.targetColumn 横向滚动到指定的列号
* @param {Function} options.success 操作结束的回调函数
*/
export function scroll(options = {}){
let {
scrollLeft,
scrollTop,
targetRow,
targetColumn,
success
} = {...options}
if(scrollLeft != null){
if(getObjType(scrollLeft) != 'number'){
return tooltip.info("The scrollLeft parameter is invalid.", "");
}
$("#luckysheet-scrollbar-x").scrollLeft(scrollLeft);
}
else if(targetColumn != null){
if(getObjType(targetColumn) != 'number'){
return tooltip.info("The targetColumn parameter is invalid.", "");
}
let col = Store.visibledatacolumn[targetColumn],
col_pre = targetColumn <= 0 ? 0 : Store.visibledatacolumn[targetColumn - 1];
$("#luckysheet-scrollbar-x").scrollLeft(col_pre);
}
if(scrollTop != null){
if(getObjType(scrollTop) != 'number'){
return tooltip.info("The scrollTop parameter is invalid.", "");
}
$("#luckysheet-scrollbar-y").scrollTop(scrollTop);
}
else if(targetRow != null){
if(getObjType(targetRow) != 'number'){
return tooltip.info("The targetRow parameter is invalid.", "");
}
let row = Store.visibledatarow[targetRow],
row_pre = targetRow <= 0 ? 0 : Store.visibledatarow[targetRow - 1];
$("#luckysheet-scrollbar-y").scrollTop(row_pre);
}
if (success && typeof success === 'function') {
success();
}
}
/**
* 根据窗口大小自动resize画布
*
* @param {Object} options 可选参数
* @param {Function} options.success 操作结束的回调函数
*/
@ -4666,6 +4895,200 @@ export function resize(options = {}){
}
/**
* 返回指定选区截图后生成的base64格式的图片
* @param {Object} options 可选参数
* @param {Object | String} options.range 选区范围只能为单个选区默认为当前选区
*/
export function getScreenshot(options = {}) {
let {
range = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1],
} = {...options}
if(getObjType(range) == 'string'){
if(!formula.iscelldata(range)){
return tooltip.info("The range parameter is invalid.", "");
}
let cellrange = formula.getcellrange(range);
range = {
"row": cellrange.row,
"column": cellrange.column
};
}
if(getObjType(range) != 'object' || range.row == null || range.column == null){
return tooltip.info("The range parameter is invalid.", "");
}
let str = range.row[0],
edr = range.row[1],
stc = range.column[0],
edc = range.column[1];
let has_PartMC = hasPartMC(Store.config, str, edr, stc, edc);
if(has_PartMC){
return tooltip.info('Cannot perform this operation on partially merged cells', '');
}
let visibledatarow = Store.visibledatarow;
let visibledatacolumn = Store.visibledatacolumn;
let scrollHeight, rh_height;
if (str - 1 < 0) {
scrollHeight = 0;
rh_height = visibledatarow[edr];
}
else {
scrollHeight = visibledatarow[str - 1];
rh_height = visibledatarow[edr] - visibledatarow[str - 1];
}
let scrollWidth, ch_width;
if (stc - 1 < 0) {
scrollWidth = 0;
ch_width = visibledatacolumn[edc];
}
else {
scrollWidth = visibledatacolumn[stc - 1];
ch_width = visibledatacolumn[edc] - visibledatacolumn[stc - 1];
}
let newCanvas = $("<canvas>").attr({
width: Math.ceil(ch_width * Store.devicePixelRatio),
height: Math.ceil(rh_height * Store.devicePixelRatio)
}).css({ width: ch_width, height: rh_height });
luckysheetDrawMain(scrollWidth, scrollHeight, ch_width, rh_height, 1, 1, null, null, newCanvas);
let ctx_newCanvas = newCanvas.get(0).getContext("2d");
//补上 左边框和上边框
ctx_newCanvas.beginPath();
ctx_newCanvas.moveTo(
0,
0
);
ctx_newCanvas.lineTo(
0,
Store.devicePixelRatio * rh_height
);
ctx_newCanvas.lineWidth = Store.devicePixelRatio * 2;
ctx_newCanvas.strokeStyle = luckysheetdefaultstyle.strokeStyle;
ctx_newCanvas.stroke();
ctx_newCanvas.closePath();
ctx_newCanvas.beginPath();
ctx_newCanvas.moveTo(
0,
0
);
ctx_newCanvas.lineTo(
Store.devicePixelRatio * ch_width,
0
);
ctx_newCanvas.lineWidth = Store.devicePixelRatio * 2;
ctx_newCanvas.strokeStyle = luckysheetdefaultstyle.strokeStyle;
ctx_newCanvas.stroke();
ctx_newCanvas.closePath();
let url = newCanvas.get(0).toDataURL("image/png");
return url;
}
/**
* 设置工作簿名称
* @param {String} name 工作簿名称
* @param {Object} options 可选参数
* @param {Function} options.success 操作结束的回调函数
*/
export function setWorkbookName(name, options = {}) {
if(name == null || name.toString().length == 0){
return tooltip.info("The name parameter is invalid.", "");
}
$("#luckysheet_info_detail_input").val(name);
let {
success
} = {...options}
if (success && typeof success === 'function') {
success();
}
}
/**
* 撤销当前操作返回刚刚撤销的操作对象
* @param {Object} options 可选参数
* @param {Function} options.success 操作结束的回调函数
*/
export function undo(options = {}) {
let ctr = $.extend(true, {}, Store.jfredo[Store.jfredo.length - 1]);
controlHistory.redo(new Event('custom'));
luckysheetactiveCell();
let {
success
} = {...options}
setTimeout(() => {
if (success && typeof success === 'function') {
success();
}
}, 1);
return ctr;
}
/**
* 重做当前操作返回刚刚重做的操作对象
* @param {Object} options 可选参数
* @param {Function} options.success 操作结束的回调函数
*/
export function redo(options = {}) {
let ctr = $.extend(true, {}, Store.jfundo[Store.jfundo.length - 1]);
controlHistory.undo(new Event('custom'));
luckysheetactiveCell();
let {
success
} = {...options}
setTimeout(() => {
if (success && typeof success === 'function') {
success();
}
}, 1);
return ctr;
}
/**
* 返回所有工作表配置
*/
export function getAllSheets() {
let data = $.extend(true, [], Store.luckysheetfile);
data.forEach((item, index, arr) => {
if(item.data != null && item.data.length > 0){
item.celldata = sheetmanage.getGridData(item.data);
}
delete item.load;
})
return data;
}
/**
* 根据index获取sheet页配置
*
@ -4796,18 +5219,39 @@ export function getLuckysheetfile(){
* @param {Function} options.success 操作结束的回调函数
*/
export function transToCellData(data, options = {}){
let {
success
} = {...options}
setTimeout(()=>{
if (success && typeof success === 'function') {
success();
}
},0)
return sheetmanage.getGridData(data)
}
/**
* celldata => data celldata一维数组数据转化成表格所需二维数组
*
* @param {Array} celldata 二维数组数据
* @param {Object} options 可选参数
* @param {Function} options.success 操作结束的回调函数
*/
export function transToData(celldata, options = {}){
let {
success
} = {...options}
setTimeout(()=>{
if (success && typeof success === 'function') {
success();
}
},0)
return sheetmanage.buildGridData({
celldata: celldata
})
}

313
src/global/getRowlen.js

@ -2,7 +2,7 @@ import { luckysheetfontformat } from '../utils/util';
import menuButton from '../controllers/menuButton';
import { getcellvalue,checkstatusByCell } from './getdata';
import { colLocationByIndex } from './location';
import { hasChinaword, isRealNull } from './validate';
import { hasChinaword, isRealNull,checkWordByteLength } from './validate';
import { isInlineStringCell } from '../controllers/inlineString';
import Store from '../store';
@ -649,7 +649,7 @@ function getCellTextInfo(cell , ctx, option){
textContent.rotate = rt;
rt = Math.abs(rt);
let anchor = 0, preHeight = 0, preWidth=0, preStr, preTextHeight, preTextWidth, i=1, wrapStyle={};
let anchor = 0, preHeight = 0, preWidth=0, preStr, preTextHeight, preTextWidth, preMeasureText, i=1, wrapStyle={}, spaceOrTwoByte=null, spaceOrTwoByteIndex=null;
if(isInline){
while(i <= inlineStringArr.length){
let shareCells = inlineStringArr.slice(anchor, i);
@ -722,6 +722,7 @@ function getCellTextInfo(cell , ctx, option){
}
textWidth += sc.measureText.width;
textHeight += sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent;
// console.log(sc.v,sc.measureText.width,sc.measureText.actualBoundingBoxAscent,sc.measureText.actualBoundingBoxDescent);
}
let width = textWidth * Math.cos(rt*Math.PI/180) + textHeight * Math.sin(rt*Math.PI/180);//consider text box wdith and line height
@ -729,31 +730,71 @@ function getCellTextInfo(cell , ctx, option){
let height = textWidth * Math.sin(rt*Math.PI/180) + textHeight * Math.cos(rt*Math.PI/180);//consider text box wdith and line height
// textW_all += textW;
let lastWord = shareCells[shareCells.length-1];
if(lastWord.v==" " || checkWordByteLength(lastWord.v)==2){
spaceOrTwoByteIndex = i;
}
if(rt!=0){//rotate
// console.log("all",anchor, i , str);
if((height+space_height)>cellHeight && text_all_split[splitIndex]!=null && tb=="2"){
// console.log(height,space_height, cellHeight);
if((height+space_height)>cellHeight && text_all_split[splitIndex]!=null && tb=="2" && i!= inlineStringArr.length){
// console.log("cut",anchor, i , str);
anchor = i-1;
for(let s=0;s<shareCells.length-1;s++){
let sc = shareCells[s];
text_all_split[splitIndex].push({
content:sc.v,
style:sc,
width:sc.measureText.width,
height:sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent,
left:0,
top:0,
splitIndex:splitIndex,
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
if(spaceOrTwoByteIndex!=null && spaceOrTwoByteIndex<i){
for(let s=0;s<spaceOrTwoByteIndex-anchor;s++){
let sc = shareCells[s];
text_all_split[splitIndex].push({
content:sc.v,
style:sc,
width:sc.measureText.width,
height:sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent,
left:0,
top:0,
splitIndex:splitIndex,
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
}
anchor = spaceOrTwoByteIndex;
i = spaceOrTwoByteIndex + 1;
splitIndex +=1;
spaceOrTwoByteIndex = null;
}
splitIndex +=1;
else{
anchor = i-1;
for(let s=0;s<shareCells.length-1;s++){
let sc = shareCells[s];
text_all_split[splitIndex].push({
content:sc.v,
style:sc,
width:sc.measureText.width,
height:sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent,
left:0,
top:0,
splitIndex:splitIndex,
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
}
splitIndex +=1;
}
}
else if(i== inlineStringArr.length){
// console.log("last",anchor, i , str);
@ -786,28 +827,59 @@ function getCellTextInfo(cell , ctx, option){
}
}
else{//plain
if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null && tb=="2"){
anchor = i-1;
if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null && tb=="2" && i!= inlineStringArr.length){
for(let s=0;s<shareCells.length-1;s++){
let sc = shareCells[s];
text_all_split[splitIndex].push({
content:sc.v,
style:sc,
width:sc.measureText.width,
height:sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent,
left:0,
top:0,
splitIndex:splitIndex,
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
if(spaceOrTwoByteIndex!=null && spaceOrTwoByteIndex<i){
for(let s=0;s<spaceOrTwoByteIndex-anchor;s++){
let sc = shareCells[s];
text_all_split[splitIndex].push({
content:sc.v,
style:sc,
width:sc.measureText.width,
height:sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent,
left:0,
top:0,
splitIndex:splitIndex,
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
}
anchor = spaceOrTwoByteIndex;
i = spaceOrTwoByteIndex + 1;
splitIndex +=1;
spaceOrTwoByteIndex = null;
}
else{
anchor = i-1;
splitIndex +=1;
for(let s=0;s<shareCells.length-1;s++){
let sc = shareCells[s];
text_all_split[splitIndex].push({
content:sc.v,
style:sc,
width:sc.measureText.width,
height:sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent,
left:0,
top:0,
splitIndex:splitIndex,
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
}
splitIndex +=1;
}
}
else if(i== inlineStringArr.length){
if(text_all_split[splitIndex]==null){
@ -854,29 +926,75 @@ function getCellTextInfo(cell , ctx, option){
let width = textWidth * Math.cos(rt*Math.PI/180) + textHeight * Math.sin(rt*Math.PI/180);//consider text box wdith and line height
let height = textWidth * Math.sin(rt*Math.PI/180) + textHeight * Math.cos(rt*Math.PI/180);//consider text box wdith and line height
let lastWord = str.substr(str.length-1,1);
if(lastWord==" " || checkWordByteLength(lastWord)==2){
spaceOrTwoByte = {
index:i,
str:preStr,
width:preTextWidth,
height:preTextHeight,
asc:preMeasureText.actualBoundingBoxAscent,
desc:preMeasureText.actualBoundingBoxDescent,
};
}
// textW_all += textW;
// console.log(str,anchor,i);
if(rt!=0){//rotate
// console.log("all",anchor, i , str);
if((height+space_height)>cellHeight && text_all_split[splitIndex]!=null){
if((height+space_height)>cellHeight && text_all_split[splitIndex]!=null && i!= value.length){
// console.log("cut",anchor, i , str);
anchor = i-1;
text_all_split[splitIndex].push({
content:preStr,
style:fontset,
left:0,
top:0,
splitIndex:splitIndex,
height:preTextHeight,
width:preTextWidth,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
splitIndex +=1;
if(spaceOrTwoByte!=null && spaceOrTwoByte.index<i){
anchor = spaceOrTwoByte.index;
i = spaceOrTwoByte.index + 1;
text_all_split[splitIndex].push({
content:spaceOrTwoByte.str,
style:fontset,
width:spaceOrTwoByte.width,
height:spaceOrTwoByte.height,
left:0,
top:0,
splitIndex:splitIndex,
asc:spaceOrTwoByte.asc,
desc:spaceOrTwoByte.desc,
fs:fontSize,
});
// console.log(1,anchor,i,splitIndex , spaceOrTwoByte.str);
splitIndex +=1;
spaceOrTwoByte = null;
}
else{
anchor = i-1;
text_all_split[splitIndex].push({
content:preStr,
style:fontset,
left:0,
top:0,
splitIndex:splitIndex,
height:preTextHeight,
width:preTextWidth,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
// console.log(2,anchor,i, splitIndex, preStr);
splitIndex +=1;
}
}
else if(i== value.length){
// console.log("last",anchor, i , str);
@ -905,24 +1023,58 @@ function getCellTextInfo(cell , ctx, option){
}
}
else{//plain
if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null){
anchor = i-1;
text_all_split[splitIndex].push({
content:preStr,
style:fontset,
width:preTextWidth,
height:preTextHeight,
left:0,
top:0,
splitIndex:splitIndex,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
splitIndex +=1;
if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null && i!= value.length){
// console.log(spaceOrTwoByte, i, anchor);
if(spaceOrTwoByte!=null && spaceOrTwoByte.index<i){
anchor = spaceOrTwoByte.index;
i = spaceOrTwoByte.index + 1;
text_all_split[splitIndex].push({
content:spaceOrTwoByte.str,
style:fontset,
width:spaceOrTwoByte.width,
height:spaceOrTwoByte.height,
left:0,
top:0,
splitIndex:splitIndex,
asc:spaceOrTwoByte.asc,
desc:spaceOrTwoByte.desc,
fs:fontSize,
});
splitIndex +=1;
spaceOrTwoByte = null;
}
else{
spaceOrTwoByte = null;
anchor = i-1;
text_all_split[splitIndex].push({
content:preStr,
style:fontset,
width:preTextWidth,
height:preTextHeight,
left:0,
top:0,
splitIndex:splitIndex,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
// console.log(2);
splitIndex +=1;
}
}
else if(i== value.length){
if(text_all_split[splitIndex]==null){
@ -954,8 +1106,11 @@ function getCellTextInfo(cell , ctx, option){
preStr = str;
preTextHeight = textHeight;
preTextWidth = textWidth;
preMeasureText = measureText;
}
// console.log(text_all_split)
}
let split_all_size = [], oneLinemaxWordCount=0;
@ -1479,6 +1634,8 @@ function drawLineInfo(wordGroup, cancelLine,underLine,option){
}
}
export {
rowlenByRange,
computeRowlenArr,

5
src/global/setdata.js

@ -15,13 +15,16 @@ function setcellvalue(r, c, d, v) {
let vupdate;
if(getObjType(v) == "object"){
if(cell==null){
if(cell == null){
cell = v;
}
else{
if(v.f != null){
cell.f = v.f;
}
else{
delete cell.f;
}
if(v.spl != null){
cell.spl = v.spl;

7
src/global/validate.js

@ -188,6 +188,12 @@ function hasPartMC(cfg, r1, r2, c1, c2) {
return hasPartMC;
}
//获取单个字符的字节数
function checkWordByteLength(value) {
return Math.ceil(value.charCodeAt().toString(2).length / 8);
}
export {
isRealNull,
isRealNum,
@ -195,4 +201,5 @@ export {
hasChinaword,
isEditMode,
hasPartMC,
checkWordByteLength
}

4
src/index.html

@ -55,7 +55,7 @@
],
data:
[sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart,sheetPicture,sheetDataVerification]
/*[{"name":"Sheet1","config":{"columnlen":{"0":241},"rowlen":{"0":81}},"index":"1","status":"1","order":"0","luckysheet_select_save":[{"row":[0,0],"column":[4,4],"sheetIndex":1}],"zoomRatio":1,"showGridLines":"1","defaultColWidth":72,"defaultRowHeight":18,"celldata":[
/*[{"name":"Sheet1","config":{"columnlen":{"0":241},"rowlen":{"0":81,"17":100}},"index":"1","status":"1","order":"0","luckysheet_select_save":[{"row":[0,0],"column":[4,4],"sheetIndex":1}],"zoomRatio":1,"showGridLines":"1","defaultColWidth":72,"defaultRowHeight":18,"celldata":[
{"r":0,"c":0,
"v":{
"ct":{
@ -93,7 +93,7 @@
"qp":1,
}
},
{"r":17,"c":2,"v":{"v":"Luckysheet","ct":{"fa":"General","t":"g"},"bg":null,"bl":0,"it":0,"ff":0,"fs":"11","fc":"rgb(51, 51, 51)","ht":1,"vt":1,"m":"Luckysheet"}}
{"r":17,"c":2,"v":{"v":"Luckysheet is good project, this is true","ct":{"fa":"General","t":"g"},"bg":null,"bl":0,"it":0,"ff":0,"fs":"11","fc":"rgb(51, 51, 51)","ht":1,"vt":1,tb:2,"m":"Luckysheet"}}
],"calcChain":[]}]*/
/*

1
src/store/index.js

@ -132,6 +132,7 @@ const Store = {
inlineStringEditRange:null,
fontList:[],
defaultFontSize: 10,
currentSheetView:"viewNormal",

2
src/utils/util.js

@ -357,7 +357,7 @@ function luckysheetfontformat(format) {
//font-size/line-height
if (!format.fs) {
font += "10pt ";
font += Store.luckysheetfontformat + "pt ";
}
else {
font += Math.ceil(format.fs) + "pt ";

Loading…
Cancel
Save