<!DOCTYPE html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>spreadJs-demo</title>
<link rel="stylesheet" type="text/css" href="css/gc.spread.sheets.excel2013white.12.0.0.css">
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script src="js/spread/gc.spread.sheets.all.12.0.0.min.js" type="text/javascript"></script>
<script src="js/spread/gc.spread.sheets.resources.zh.12.0.0.min.js" type="text/javascript"></script>
<script src="js/utils.js" type="text/javascript"></script>
</head>
<body>
<input type="text" id="inputValue"/>
<input type="button" id="searchBtn" value="搜索" />
<!-- <input type="button" id="searchBtn" value="搜索" /> -->
<span>罐子类型</span>
<select id="viewType">
<option value="" selected="selected">全部</option>
<option value="存钱罐">存钱罐</option>
<option value="大富翁">大富翁</option>
</select>
<span>月度目标差额</span>
<select id="monthCE">
<option value="" selected="selected">全部</option>
<option value="Y">已完成</option>
<option value="N">未完成</option>
</select>
<span>历史完成月度</span>
<select id="hisCompletedMonth">
<option value="" selected="selected">全部</option>
<option value="1个月">Y</option>
<option value="x个月">N</option>
</select>
<span>上月是否完成规划</span>
<select id="hasCompletedMonthPlan">
<option value="" selected="selected">全部</option>
<option value="Y">Y</option>
<option value="N">N</option>
</select>
<div id="ss" style="margin:0 auto;width:1250px;height:860px;border:1px solid black;"></div>
</body>
<script type="text/javascript" src="js/esheetSearch.js"></script>
<script type="text/javascript">
var param=window.location.search;
var spreadNS = GC.Spread.Sheets;
var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'));
var activeSheet = spread.getSheet(0);
//影藏sheet添加符号
spread.options.newTabVisible=false;
var columnNums=0;
window.onload = function() {
$.ajax({
type: "POST",
url: "http://localhost:8080/getData.do"+param+"&r="+ new Date().getTime(),
async: false,
success: function(data){
var obj=data.Data;
var header=data.Header
columnNums=data.columnNum;
activeSheet.suspendPaint();
//表头三行
activeSheet.setRowCount(2, GC.Spread.Sheets.SheetArea.colHeader);
activeSheet.setValue(0, 0, "群名", GC.Spread.Sheets.SheetArea.colHeader);
activeSheet.addSpan(0,1,1,2,GC.Spread.Sheets.SheetArea.colHeader);
activeSheet.setValue(0, 1, header[0], GC.Spread.Sheets.SheetArea.colHeader);
activeSheet.setValue(0, 3, "当月加保人数", GC.Spread.Sheets.SheetArea.colHeader);
activeSheet.setValue(0, 4, header[1], GC.Spread.Sheets.SheetArea.colHeader);
activeSheet.setValue(0, 5, "当月金额", GC.Spread.Sheets.SheetArea.colHeader);
activeSheet.setValue(0, 6, header[2], GC.Spread.Sheets.SheetArea.colHeader);
activeSheet.setValue(0, 7, "本月完成规划人数", GC.Spread.Sheets.SheetArea.colHeader);
activeSheet.setValue(0, 8, header[3], GC.Spread.Sheets.SheetArea.colHeader);
activeSheet.setValue(0, 9, "上月完成规划人数", GC.Spread.Sheets.SheetArea.colHeader);
activeSheet.setValue(0, 10, header[4], GC.Spread.Sheets.SheetArea.colHeader);
// activeSheet.setValue(0, 11, "退保用户", GC.Spread.Sheets.SheetArea.colHeader);
var cellType = new GC.Spread.Sheets.CellTypes.Button();
cellType.buttonBackColor("#FF0000");
cellType.text("退保用户");
activeSheet.getCell(0, 11,GC.Spread.Sheets.SheetArea.colHeader).cellType(cellType);
activeSheet.addSpan(0, 12, 1, 65, GC.Spread.Sheets.SheetArea.colHeader);
var defaultStyle = new GC.Spread.Sheets.Style();
defaultStyle.hAlign = GC.Spread.Sheets.HorizontalAlign.center;
activeSheet.setDefaultStyle(defaultStyle, GC.Spread.Sheets.SheetArea.viewport);
//Change the column header height.
activeSheet.setRowHeight(0, 60.0,GC.Spread.Sheets.SheetArea.colHeader);
activeSheet.setRowHeight(1, 30.0,GC.Spread.Sheets.SheetArea.colHeader);
//Change the row header width.
// activeSheet.setColumnWidth(1, 150.0,GC.Spread.Sheets.SheetArea.colHeader);
// activeSheet.addSpan(0,);
// activeSheet.setRowHeight(1, 50);
// activeSheet.setColumnWidth(0, 150);
activeSheet.autoGenerateColumns = true;
activeSheet.options.allowCellOverflow = true;
activeSheet.setDataSource(obj);
activeSheet.defaults.rowHeight = 50;
// activeSheet.defaults.columnWidth = 100;
activeSheet.getRange(-1, 1, -1, columnNums-1, GC.Spread.Sheets.SheetArea.viewport).width(120);
// activeSheet.getRange(1, 1, 1, 3).backColor("rgb(20, 140, 1218)");
var row = activeSheet.getRange(1, -1, 1, -1, spreadNS.SheetArea.colHeader);
row.backColor("yellow");
activeSheet.autoFitColumn;
// activeSheet.autoFitRow
//行添加yanse
for(var i=0;i<obj.length;i++){
if(obj[i].罐子区分=='大富翁'){
activeSheet.getRange(i, -1, 1, -1, spreadNS.SheetArea.viewport).backColor("Pink");
}
}
//隐藏列
var instance = new GC.Spread.Sheets.CellRange(activeSheet, -1, columnNums, -1, 3, spreadNS.SheetArea.viewport);
instance.visible(false);
//自动调整行高列宽 参数为第几列
activeSheet.autoFitColumn(0);
// activeSheet.autoFitColumn(1);
activeSheet.autoFitColumn(4);
activeSheet.setColumnWidth(5, 240.0,GC.Spread.Sheets.SheetArea.colHeader);
// activeSheet.getRange(0, -1, obj.length, -1, GC.Spread.Sheets.SheetArea.viewport).height(150);
/* var instance = new GC.Spread.Sheets.CellRange(activeSheet, 0, -1, obj.length, -1, GC.Spread.Sheets.SheetArea.viewport);
instance.height(100); */
for(var i=0;i<obj.length;i++){
var text=activeSheet.getCell(i,5).value();
if(!(typeof text == "undefined" || text == null || text == "" || text.length<30)){
activeSheet.getCell(i,5).wordWrap(true);
activeSheet.autoFitRow(i);
}
}
// activeSheet.setColumnWidth(5, 240.0,GC.Spread.Sheets.SheetArea.colHeader);
//筛选
var filter = new spreadNS.Filter.HideRowFilter(new spreadNS.Range(-1, columnNums-4, -1, 4));
activeSheet.rowFilter(filter);
filter.filterButtonVisible(true);
//居中
var style = new GC.Spread.Sheets.Style();
style.hAlign = GC.Spread.Sheets.HorizontalAlign.center;
style.vAlign = GC.Spread.Sheets.VerticalAlign.center;
style.wordWrap = true;
activeSheet.setStyle(-1,-1,style,GC.Spread.Sheets.SheetArea.viewport);
//边框
activeSheet.getRange(-1, -1, -1, -1).setBorder(new spreadNS.LineBorder('black', spreadNS.LineStyle.thin), { all: true });
spread.sheets[0].name(header[0]);
//单元格值改变事件
spread.bind(spreadNS.Events.ValueChanged, function (e, args) {
console.log(args);
if(args.col==5){
// alert(args.newValue);
if(confirm("确认保存修改么?")){
alert(activeSheet.getValue(1,columnNums+1));
var viewId=activeSheet.getValue(args.row,columnNums);
var userId=activeSheet.getValue(args.row,columnNums+1);
var msg=args.newValue;
submitMessage_bgg(args.newValue,userId,viewId)
$.ajax({
type: "POST",
url: "url",
dataType: "json",
data: "userId=" + userId+"&remark="+msg+"&viewId="+viewId,
async: false,
success: function(data) {
var result = data.result;
if(result == 1){
alert("修改成功");
activeSheet.getCell(args.row,args.col).wordWrap(true);
activeSheet.autoFitRow(args.row);
}else{
alert("修改失败")
}
}
});
}
}
});
activeSheet.resumePaint();
}
});
}
</script>
</html>
esheetSearch.js
$(function(){
//自定已筛选
function CustomFilter(){
GC.Spread.Sheets.ConditionalFormatting.Condition.apply(this, arguments);
};
CustomFilter.prototype = new GC.Spread.Sheets.ConditionalFormatting.Condition();
CustomFilter.prototype.evaluate = function (evaluator, row, col) {
var value = evaluator.getValue(row, col);
if (value !== '' && isNumber(value.trim())) {
return true;
} else {
return false;
}
};
document.getElementById('searchBtn').onclick = function() {
var sheet = spread.getActiveSheet();
var searchCondition = getSearchCondition();
var searchResult = null;
var sels = sheet.getSelections();
if (sels.length > 1) {
searchCondition.searchFlags |= spreadNS.Search.SearchFlags.blockRange;
} else if (sels.length == 1) {
var spanInfo = getSpanInfo(sheet, sels[0].row, sels[0].col);
if (sels[0].rowCount != spanInfo.rowSpan && sels[0].colCount != spanInfo.colSpan) {
searchCondition.searchFlags |= spreadNS.Search.SearchFlags.blockRange;
}
}
searchResult = getResultSearchinSheetEnd(searchCondition);
if (searchResult == null || searchResult.searchFoundFlag == spreadNS.Search.SearchFoundFlags.none) {
searchResult = getResultSearchinSheetBefore(searchCondition);
}
if (searchResult != null && searchResult.searchFoundFlag != spreadNS.Search.SearchFoundFlags.none) {
spread.setActiveSheetIndex(searchResult.foundSheetIndex);
var sheet = spread.getActiveSheet();
sheet.setActiveCell(searchResult.foundRowIndex, searchResult.foundColumnIndex);
if ((searchCondition.searchFlags & spreadNS.Search.SearchFlags.blockRange) == 0) {
sheet.setActiveCell(searchResult.foundRowIndex, searchResult.foundColumnIndex, 1, 1);
}
//scrolling
if (searchResult.foundRowIndex < sheet.getViewportTopRow(1) ||
searchResult.foundRowIndex > sheet.getViewportBottomRow(1) ||
searchResult.foundColumnIndex < sheet.getViewportLeftColumn(1) ||
searchResult.foundColumnIndex > sheet.getViewportRightColumn(1)
) {
sheet.showCell(searchResult.foundRowIndex,
searchResult.foundColumnIndex,
spreadNS.VerticalPosition.center,
spreadNS.HorizontalPosition.center);
} else {
sheet.repaint();
}
} else {
//Not Found
alert('Not Found');
}
};
//罐子类型筛选
$("#viewType").change(function(){
var sheet = spread.getActiveSheet(),
filter = sheet.rowFilter(),
value = $("#viewType").val();
col = columnNums-1;
if (filter) {
if(''==value){
value="*";
}
filter.removeFilterItems(col);
var condition = new spreadNS.ConditionalFormatting.Condition(spreadNS.ConditionalFormatting.ConditionType.textCondition, {
compareType: spreadNS.ConditionalFormatting.TextCompareType.contains,
expected: value
});
filter.addFilterItem(col, condition);
filter.filter();
sheet.invalidateLayout();
sheet.repaint();
}
});
//月度差额
$("#monthCE").change(function(){
var sheet = spread.getActiveSheet(),
filter = sheet.rowFilter(),
value = $("#monthCE").val();
col = columnNums-4;
if (filter) {
if(''==value){
value="*";
}else if("Y"==value){
value='已完成';
}
filter.removeFilterItems(col);
var condition = new spreadNS.ConditionalFormatting.Condition(spreadNS.ConditionalFormatting.ConditionType.textCondition, {
compareType: spreadNS.ConditionalFormatting.TextCompareType.contains,
expected: value
});
if('N'==value){
var condition1 = new spreadNS.ConditionalFormatting.Condition(spreadNS.ConditionalFormatting.ConditionType.textCondition, {
compareType: spreadNS.ConditionalFormatting.TextCompareType.doesNotContain,
expected: '已完成'
});
var condition2 = new spreadNS.ConditionalFormatting.Condition(spreadNS.ConditionalFormatting.ConditionType.textCondition, {
compareType: spreadNS.ConditionalFormatting.TextCompareType.notEqualsTo,
expected: ''
});
var conditions=getComplexCondition(condition1,condition2);
filter.addFilterItem(col, conditions);
}else{
filter.addFilterItem(col, condition);
}
filter.filter();
sheet.invalidateLayout();
sheet.repaint();
}
});
//历史完成月度
$("#hisCompletedMonth").change(function(){
var sheet = spread.getActiveSheet(),
filter = sheet.rowFilter(),
value = $("#hisCompletedMonth").val();
col = columnNums-3;
if (filter) {
if(''==value){
value="*";
}else if('1个月'==value){
value='/1个月';
}
filter.removeFilterItems(col);
var condition = new spreadNS.ConditionalFormatting.Condition(spreadNS.ConditionalFormatting.ConditionType.textCondition, {
compareType: spreadNS.ConditionalFormatting.TextCompareType.contains,
expected: value
});
if('x个月'==value){
var condition1 = new spreadNS.ConditionalFormatting.Condition(spreadNS.ConditionalFormatting.ConditionType.textCondition, {
compareType: spreadNS.ConditionalFormatting.TextCompareType.doesNotContain,
expected: '/1个月'
});
var condition2 = new spreadNS.ConditionalFormatting.Condition(spreadNS.ConditionalFormatting.ConditionType.textCondition, {
compareType: spreadNS.ConditionalFormatting.TextCompareType.notEqualsTo,
expected: ''//null也可以
});
/* var condition2 = new GC.Spread.Sheets.ConditionalFormatting.Condition(GC.Spread.Sheets.ConditionalFormatting.ConditionType.formulaCondition,{
compareType: GC.Spread.Sheets.ConditionalFormatting.CustomValueType.nonEmpty
});*/
var conditions=getComplexCondition(condition1,condition2);
filter.addFilterItem(col, conditions);
}else{
filter.addFilterItem(col, condition);
}
filter.filter();
sheet.invalidateLayout();
sheet.repaint();
}
});
//上月是否完成规划
$("#hasCompletedMonthPlan").change(function(){
var sheet = spread.getActiveSheet(),
filter = sheet.rowFilter(),
value = $("#hasCompletedMonthPlan").val();
col = columnNums-2;
if (filter) {
if(''==value){
value="*";
}
filter.removeFilterItems(col);
var condition = new spreadNS.ConditionalFormatting.Condition(spreadNS.ConditionalFormatting.ConditionType.textCondition, {
compareType: spreadNS.ConditionalFormatting.TextCompareType.contains,
expected: value
});
filter.addFilterItem(col, condition);
filter.filter();
sheet.invalidateLayout();
sheet.repaint();
}
});
});
function getComplexCondition(condition1,condition2){
var conditions = new GC.Spread.Sheets.ConditionalFormatting.Condition(GC.Spread.Sheets.ConditionalFormatting.ConditionType.relationCondition, {
compareType: spreadNS.ConditionalFormatting.LogicalOperators.and,
item1: condition1,
item2: condition2
});
return conditions;
}
function getSpanInfo(sheet, row, col) {
var span = sheet.getSpans(new spreadNS.Range(row, col, 1, 1));
if (span.length > 0) {
return {
rowSpan : span[0].rowCount,
colSpan : span[0].colCount
};
} else {
return {
rowSpan : 1,
colSpan : 1
};
}
}
function getResultSearchinSheetEnd(searchCondition) {
var sheet = spread.getActiveSheet();
searchCondition.startSheetIndex = spread.getActiveSheetIndex();
searchCondition.endSheetIndex = spread.getActiveSheetIndex();
if (searchCondition.searchOrder == spreadNS.Search.SearchOrder.zOrder) {
searchCondition.findBeginRow = sheet.getActiveRowIndex();
searchCondition.findBeginColumn = sheet.getActiveColumnIndex() + 1;
} else if (searchCondition.searchOrder == spreadNS.Search.SearchOrder.nOrder) {
searchCondition.findBeginRow = sheet.getActiveRowIndex() + 1;
searchCondition.findBeginColumn = sheet.getActiveColumnIndex();
}
if ((searchCondition.searchFlags & spreadNS.Search.SearchFlags.blockRange) > 0) {
var sel = sheet.getSelections()[0];
searchCondition.rowStart = sel.row;
searchCondition.columnStart = sel.col;
searchCondition.rowEnd = sel.row + sel.rowCount - 1;
searchCondition.columnEnd = sel.col + sel.colCount - 1;
}
var searchResult = spread.search(searchCondition);
return searchResult;
}
function getResultSearchinSheetBefore(searchCondition) {
var sheet = spread.getActiveSheet();
searchCondition.startSheetIndex = spread.getActiveSheetIndex();
searchCondition.endSheetIndex = spread.getActiveSheetIndex();
if ((searchCondition.searchFlags & spreadNS.Search.SearchFlags.blockRange) > 0) {
var sel = sheet.getSelections()[0];
searchCondition.rowStart = sel.row;
searchCondition.columnStart = sel.col;
searchCondition.findBeginRow = sel.row;
searchCondition.findBeginColumn = sel.col;
searchCondition.rowEnd = sel.row + sel.rowCount - 1;
searchCondition.columnEnd = sel.col + sel.colCount - 1;
} else {
searchCondition.rowStart = -1;
searchCondition.columnStart = -1;
searchCondition.findBeginRow = -1;
searchCondition.findBeginColumn = -1;
searchCondition.rowEnd = sheet.getActiveRowIndex();
searchCondition.columnEnd = sheet.getActiveColumnIndex();
}
var searchResult = spread.search(searchCondition);
return searchResult;
}
function getResultSearchinWorkbookEnd(searchCondition) {
searchCondition.rowStart = -1;
searchCondition.columnStart = -1;
searchCondition.findBeginRow = -1;
searchCondition.findBeginColumn = -1;
searchCondition.rowEnd = -1;
searchCondition.columnEnd = -1;
searchCondition.startSheetIndex = spread.getActiveSheetIndex() + 1;
searchCondition.endSheetIndex = -1;
var searchResult = spread.search(searchCondition);
return searchResult;
}
function getResultSearchinWorkbookBefore(searchCondition) {
searchCondition.rowStart = -1;
searchCondition.columnStart = -1;
searchCondition.findBeginRow = -1;
searchCondition.findBeginColumn = -1;
searchCondition.rowEnd = -1;
searchCondition.columnEnd = -1;
searchCondition.startSheetIndex = -1
searchCondition.endSheetIndex = spread.getActiveSheetIndex() - 1;
var searchResult = spread.search(searchCondition);
return searchResult;
}
function getSearchCondition(searchString) {
var searchCondition = new spreadNS.Search.SearchCondition();
var searchString=$("#inputValue").val();
searchCondition.searchString = searchString;
searchCondition.startSheetIndex = spread.getActiveSheetIndex();
searchCondition.endSheetIndex = spread.getActiveSheetIndex();
searchCondition.searchOrder = spreadNS.Search.SearchOrder.zOrder;
searchCondition.searchTarget = spreadNS.Search.SearchFoundFlags.cellText;
searchCondition.searchFlags |= spreadNS.Search.SearchFlags.ignoreCase;
return searchCondition;
}