Package org.jsoup.select

Examples of org.jsoup.select.Elements


                code = buffer.toString();
               
//              将html中table提取出来,html头部等信息都不要
                Document doc = Jsoup.parse(code);
            StringBuffer sb = new StringBuffer();
            Elements elements = doc.select("table");
            for(int i=0;i<elements.size();i++){
              Element element = elements.get(i);
              sb.append(element.toString());
            }
           
//                System.out.print(code);
            code = sb.toString();
View Full Code Here


    table.attr("width",String.valueOf(totalwidth));
    return maxColumns;
  }
 
  private static void setColumnWidth(HSSFSheet sheet, Element table) {
    Elements colgroups = table.select("colgroup");
    // 首先设置列宽
    if (colgroups.size() > 0) {
      Element colgroup = colgroups.get(0);
      Elements cols = colgroup.children();
      for (int i = 0; i < cols.size(); i++) {
        Element col = cols.get(i);
        int width = DEFAULT_COLUMN_WIDTH;
        try {
          if (col.hasAttr("width")) {
            String widthS = col.attr("width");
            if(widthS.endsWith("px")){
View Full Code Here

      }
    }
  }
 
  private static void setRowHeight(HSSFSheet sheet, Element table) {
    Elements trs = table.select("tr");
    // 首先设置列宽
    if (trs.size() > 0) {
      for (int i = 0; i < trs.size(); i++) {
        Element tr = trs.get(i);
        int height = DEFAULT_ROW_HEIGHT;
        try {
          if (tr.hasAttr("height")) {
            String heightS = tr.attr("height");
            if (heightS.endsWith("px")) {
View Full Code Here

    }
  }

  private static void hideHTMLCells(Element table,int startrow,int startcolumn,int endrow,int endcolumn){
    if(table!=null){
      Elements trs = table.select("tr");
      for(int i=startrow;i<=endrow&&i<trs.size();i++){
        Element tr = trs.get(i);
        Elements tds = tr.children();
        for(int j=startcolumn;j<=endcolumn&&j<tds.size();j++){
          Element td = tds.get(j);
          if(i==startrow&&j==startcolumn){
           
          }else{
            css(td,"display","none");
          }
View Full Code Here

 
  private static void mergeCells(Element table,Sheet sheet) {
    if(table==null||sheet==null){
      return;
    }
    Elements trs = table.select("tr");
    int mergedRegions = sheet.getNumMergedRegions();
    for(int i=0;i<mergedRegions;i++){
      CellRangeAddress rangeAddress = sheet.getMergedRegion(i);
      if(rangeAddress!=null){
        int startRow = rangeAddress.getFirstRow();
        int startColumn = rangeAddress.getFirstColumn();
        int rowspan = rangeAddress.getLastRow()-startRow+1;
        int colspan = rangeAddress.getLastColumn()-startColumn+1;
        if(startRow<trs.size()){
          Element tr = trs.get(startRow);
          Elements tds = tr.children();
          if(startColumn<tds.size()){
            Element td = tds.get(startColumn);
            if(rowspan>1){
              td.attr("rowspan",String.valueOf(rowspan));
            }
            if(colspan>1){
              for(int j=0;j<rowspan;j++){
                if(startRow+j<trs.size()){
                  Element spanTr = trs.get(startRow+j);
                  Elements spanTds = spanTr.children();
                  if(startColumn<spanTds.size()){
                    Element spanTd = spanTds.get(startColumn);
                    spanTd.attr("colspan",String.valueOf(colspan));
                  }
                }
              }
            }
View Full Code Here

      }
    }
  }
 
  private static void mergeCells(HSSFSheet sheet, Element table) {
    Elements trs = table.select("tr");
    // 首先设置列宽
    if (trs.size() > 0) {
      for (int i = 0; i < trs.size(); i++) {
        Element tr = trs.get(i);
        Elements tds = tr.children();
        HSSFRow row = sheet.getRow(i);
        if (tds != null) {
          if (row == null) {
            row = sheet.createRow(i);
          }
          for (int j = 0; j < tds.size(); j++) {
            Element td = tds.get(j);
            int rowspan = 1;
            if (td.hasAttr("rowspan")) {
              try {
                rowspan = Integer.parseInt(td.attr("rowspan"));
              } catch (NumberFormatException e) {
View Full Code Here

  private static void setCellStyleAndValue(Element table,Sheet sheet,int totalColumns) {
    if(table==null||sheet==null){
      return;
    }
    Elements trs = table.select("tr");
    int firstRow = sheet.getFirstRowNum();
    int lastRow = sheet.getLastRowNum();
    for(int i=0;i<=lastRow;i++){
      if(i<trs.size()){
        Element tr = trs.get(i);
        if(i<firstRow){//代表是空Cell,直接添加一个空的td
          for(int j=0;j<totalColumns;j++){
            tr.appendElement("td");
          }
        }else{
View Full Code Here

     
    }
  }
 
  private static void setCellStyleAndValue(WorkbookStyleContainer styleContainer,HSSFSheet sheet, Element table) {
    Elements trs = table.select("tr");
    // 首先设置列宽
    if (trs.size() > 0) {
      for (int i = 0; i < trs.size(); i++) {
        Element tr = trs.get(i);
        Elements tds = tr.children();
        HSSFRow row = sheet.getRow(i);
        if (tds != null) {
          if (row == null) {
            row = sheet.createRow(i);
          }
          for (int j = 0; j < tds.size(); j++) {
            Element td = tds.get(j);
            // System.out.println(td.text());
            HSSFCell cell = null;
            if (td.hasAttr("formula")) {
              String formula = td.attr("formula");
              String excelFormula = formula;
View Full Code Here

  public OperResult renderXLSV2(String id,String html,String time,String title,String mode,Map parameterMap){
//    System.out.println(html);
    OperResult result = new OperResult();
    if(html!=null){
      Document doc = Jsoup.parseBodyFragment(html);
      Elements tables = doc.select("table");
      Workbook book = HTMLAdjustMent4J.convertHTML2Excel(tables);
      if(book!=null){
        result.setSucceed();
        result.setData(book);
//        result.setInfoMSG("报表");
View Full Code Here

 
  public OperResult renderXLS(String id,String html,Map parameterMap) {
    OperResult result = new OperResult();
    if(html!=null){
      Document doc = Jsoup.parseBodyFragment(html);
      Elements tables = doc.select("table");
      List<Workbook> books = new ArrayList<Workbook>();
      for(int i=0;i<tables.size();i++){
        Element table = tables.get(i);
        Workbook book = HTMLAdjustMent4J.convertHTML2Excel(table.toString());
        if(book!=null){
          books.add(book);
        }
      }
View Full Code Here

TOP

Related Classes of org.jsoup.select.Elements

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.