GVKun编程网logo

如何将 html 表与图像 src 一起下载为 csv(html表格中怎么导入图片)

15

对于想了解如何将html表与图像src一起下载为csv的读者,本文将提供新的信息,我们将详细介绍html表格中怎么导入图片,并且为您提供关于AndroidHTML.fromHTML()与图像?、htm

对于想了解如何将 html 表与图像 src 一起下载为 csv的读者,本文将提供新的信息,我们将详细介绍html表格中怎么导入图片,并且为您提供关于Android HTML.fromHTML()与图像?、html css 如何将表头固定_html/css_WEB-ITnose、html – CSS图像和标题 – 高度100%在一起、html – Safari iOS不支持使用srcset / sizes的响应式图像的有价值信息。

本文目录一览:

如何将 html 表与图像 src 一起下载为 csv(html表格中怎么导入图片)

如何将 html 表与图像 src 一起下载为 csv(html表格中怎么导入图片)

如何解决如何将 html 表与图像 src 一起下载为 csv?

我有一张表,我想将它导出为 csv,但该表也有图像。我知道 csv 不支持图像,但我想获取图像的 src 而不是图像文件。

示例表

<table>
    <tbody>
      <tr>
        <td>John Doe</td>
        <td>Student</td>
        <td><img src="xyz.com/image.png"></td>
      </tr>
      <tr>
        <td>Jane Doe</td>
        <td>Teacher</td>
        <td><img src="abc.com/image.png"></td>
      </tr>
    </tbody>
 </table>

解决方法

您可以在excel中下载图片和链接,如下所示。

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>


function fnExcelReport()
{
    var tab_text="<table border=''2px''><tr bgcolor=''#87AFC6''>";
    var textRange; var j=0;
    tab = document.getElementById(''headerTable''); // id of table

    for(j = 0 ; j < tab.rows.length ; j++) 
    {     
        tab_text=tab_text+tab.rows[j].innerHTML+"</tr>";
        //tab_text=tab_text+"</tr>";
    }

    tab_text=tab_text+"</table>";
    var ua = window.navigator.userAgent;
    var msie = ua.indexOf("MSIE "); 

    if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))      // If Internet Explorer
    {
        txtArea1.document.open("txt/html","replace");
        txtArea1.document.write(tab_text);
        txtArea1.document.close();
        txtArea1.focus(); 
        sa=txtArea1.document.execCommand("SaveAs",true,"Say Thanks to Sumit.xls");
    }  
    else                 //other browser not tested on IE 11
        sa = window.open(''data:application/vnd.ms-excel,'' + encodeURIComponent(tab_text));  

    return (sa);
}
</script>
</head>
<body>
<iframe id="txtArea1"></iframe>
<button id="btnExport" onclick="fnExcelReport();"> EXPORT </button>
<table id="headerTable">
    <tbody> 
    
   

      <tr>
        <td>John Doe</td>
        <td>Student</td>
        
        <td style=display:none><a href="https://www.w3schools.com/html/img_girl.jpg" target="_blank"/>Download Image</td>
        <td><img src="https://www.w3schools.com/html/img_girl.jpg"></td>
     </tr>
        
   

      <tr>
        <td>Jane Doe</td>
        <td>Teacher</td>
        
          <td style=display:none><a href="https://www.w3schools.com/html/img_girl.jpg" target="_blank"/>Download Image</td>
        <td><img src="https://www.w3schools.com/html/img_girl.jpg"></td>
     </tr>
    
    
    </tbody>
 </table>

</body>
</html>
,

适用于将来在没有 Excel 的情况下阅读本文并希望将数据格式化为 CSV 的任何人。这是如何做到的:

let rows = document.getElementsByTagName(''tr'');

let cells;
let csv = "";

let csvSeparator = ";"; // Sets the separator between fields
let quoteField = true; // Adds quotes around fields

let regex = /.*<img.*src="(.*?)"/i

for (let row = 0; row < rows.length; row++) {
  cells = rows[row].getElementsByTagName(''td'');
  if (cells.length === 0) {
    cells = rows[row].getElementsByTagName(''th'');
  }
  for (let cell = 0; cell < cells.length; cell++) {
    if (quoteField) { csv += ''"''; }
    
    if (regex.test(cells[cell].innerHTML)) {
      csv += cells[cell].innerHTML.match(regex)[1];
    } else {
      csv += cells[cell].innerText;
    }
    
    if (quoteField) { csv += ''"''; }
    
    if (cell === cells.length - 1) {
      csv += "\n";
    } else {
      csv += csvSeparator;
    }
  }
}

function downloadToFile(content,filename,contentType) {
  const a = document.createElement(''a'');
  const file = new Blob([content],{type: contentType});
  
  a.href = URL.createObjectURL(file);
  a.download = filename;
  
  // To generate a link,use this:
  a.innerHTML = "Download CSV";
  document.body.appendChild(a);

  // If you want to automatically download then use this instead:
  /*
  a.click();
    URL.revokeObjectURL(a.href);
  */
}

console.log(csv);

downloadToFile(csv,''csv-export.csv'',''text/plain'');
* {
  font-family: sans-serif;
}

table {
  border-collapse: collapse;
}

table,th,td {
  border: 1px solid #ccc;
  padding: 5px 10px;
}

a {
  text-decoration: none;
}
<table>
    <thead>
      <tr>
        <th>Name</th>
        <th>Occupation</th>
        <th>Photo</th>
      </tr>
    </thead>
    <tbody> 
      <tr>
        <td>John Doe</td>
        <td>Student</td>
        <td><img src="xyz.com/image.png"></td>
     </tr>
     <tr>
        <td>Jane Doe</td>
        <td>Teacher</td>
        <td><img src="abc.com/image.png"></td>
     </tr>
    </tbody>
 </table>

Android HTML.fromHTML()与图像?

Android HTML.fromHTML()与图像?

我的Android应用程序接收其中包含图像的HTML内容。是否可以使fromHTML()函数在接收到的HTML字符串中显示图像?

如果没有,如何获取HTML字符串中的图像并将其转换为TextView图像?

谢谢

答案1

小编典典

URLDrawable.java

public class URLDrawable extends BitmapDrawable {    // the drawable that you need to set, you could set the initial drawing    // with the loading image if you need to    protected Drawable drawable;    @Override    public void draw(Canvas canvas) {        // override the draw to facilitate refresh function later        if(drawable != null) {            drawable.draw(canvas);        }    }}

URLImageParser.java

public class URLImageParser implements ImageGetter {    Context c;    View container;    /***     * Construct the URLImageParser which will execute AsyncTask and refresh the container     * @param t     * @param c     */    public URLImageParser(View t, Context c) {        this.c = c;        this.container = t;    }    public Drawable getDrawable(String source) {        URLDrawable urlDrawable = new URLDrawable();        // get the actual source        ImageGetterAsyncTask asyncTask =             new ImageGetterAsyncTask( urlDrawable);        asyncTask.execute(source);        // return reference to URLDrawable where I will change with actual image from        // the src tag        return urlDrawable;    }    public class ImageGetterAsyncTask extends AsyncTask<String, Void, Drawable>  {        URLDrawable urlDrawable;        public ImageGetterAsyncTask(URLDrawable d) {            this.urlDrawable = d;        }        @Override        protected Drawable doInBackground(String... params) {            String source = params[0];            return fetchDrawable(source);        }        @Override        protected void onPostExecute(Drawable result) {            // set the correct bound according to the result from HTTP call            urlDrawable.setBounds(0, 0, 0 + result.getIntrinsicWidth(), 0                     + result.getIntrinsicHeight());            // change the reference of the current drawable to the result            // from the HTTP call            urlDrawable.drawable = result;            // redraw the image by invalidating the container            URLImageParser.this.container.invalidate();        }        /***         * Get the Drawable from URL         * @param urlString         * @return         */        public Drawable fetchDrawable(String urlString) {            try {                InputStream is = fetch(urlString);                Drawable drawable = Drawable.createFromStream(is, "src");                drawable.setBounds(0, 0, 0 + drawable.getIntrinsicWidth(), 0                         + drawable.getIntrinsicHeight());                 return drawable;            } catch (Exception e) {                return null;            }         }        private InputStream fetch(String urlString) throws MalformedURLException, IOException {            DefaultHttpClient httpClient = new DefaultHttpClient();            HttpGet request = new HttpGet(urlString);            HttpResponse response = httpClient.execute(request);            return response.getEntity().getContent();        }    }}

ImageGetter的用法

String html = "Hello " +"<img src=''http://www.gravatar.com/avatar/" + "f9dd8b16d54f483f22c0b7a7e3d840f9?s=32&d=identicon&r=PG''/>" +" This is a test " +"<img src=''http://www.gravatar.com/avatar/a9317e7f0a78bb10a980cadd9dd035c9?s=32&d=identicon&r=PG''/>";this.textView = (TextView)this.findViewById(R.id.textview);URLImageParser p = new URLImageParser(textView, this);Spanned htmlSpan = Html.fromHtml(html, p, null);textView.setText(htmlSpan);

html css 如何将表头固定_html/css_WEB-ITnose

html css 如何将表头固定_html/css_WEB-ITnose

position属性取值为fixed时,则元素的位置将不受滚动条的影响,而是直接依据窗口定位,这就是将表头固定的最直接方法,网上其他途径感觉都是在走弯路。但是与此同时必须解决两个问题。第一:表体将随之不依据表头定位,而是依据body元素定位,因此表体将上移,导致表体靠上部分被表头遮挡,而且有重影。第二:表体的宽高和表头的宽高也将互相独立不再受文档流的约束,这导致单元格对不齐。     解决办法示例如下。其中,单元格上下对齐的问题可以通过设置padding margin 百分比width来解决,表头和表体也可以放在各自的div里。 样式单 <style type="text/css">         *{            padding:0px;             margin: 0px;          }         #thead {           /*固定表头*/         position:fixed;          /* 表头显示层次高于表体,防止空白行和表头重合时出现重影*/                 z-index:2;         background:#ECECFF;         }         #spacetr{  /* 空白的tr 用来填补表头遮盖的数据*/         position:relative;         z-index:1;         }         .tdata { /* 显示表格数据的tr */         position:relative;         z-index:1;         }     </style>   js脚本    $(function(){ $("#spacetr").css("height",$("#thead").css("height")); //将空白行的高度设置为和表头等高,使被遮挡的数据刚好下移表头高度的距离    }); jsp代码:    <div> <%--<img  src="${pageContext.request.contextPath}/images/post_head.jpg"/ alt="html css 如何将表头固定_html/css_WEB-ITnose" >  --%>        <table id="table" border="1px gray solid "  cellspacing="0" cellpadding="0" width="100%;" >    <tr id="thead">    <td width="9%" align="center">招聘学科</td>    <c:forEach items="${postnames}" var="postname">    <td valign="bottom" align="center">    ${postname}    </td>    </c:forEach>    </tr>    <tr id="spacetr">    <td width="9%"></td>    <c:forEach items="${postnames}" var="postname">    <td>    </td>    </c:forEach>    </tr>    <c:forEach items="${shcoolsPostnumbers}" var="schoolPostnumbers">    <tr>    <td width="9%" >${schoolPostnumbers.key}</td>    <c:forEach items="${schoolPostnumbers.value}" var="postnumber">    <td align="center"> ${postnumber} </td>    </c:forEach>    </tr>    </c:forEach> </table>     </div> 
登录后复制

  

html – CSS图像和标题 – 高度100%在一起

html – CSS图像和标题 – 高度100%在一起

我的情况是需要在下方显示图像(不重叠).图像的大小和标题的长度都不知道.

整个图形元素的高度需要100%像这样:

Illustration

元素的宽度应该是动态的,由图像比率决定,标题应相应地换行.这很重要,因为我需要彼此相邻显示多个图像.

有什么方法可以用CSS实现这个目标吗?

我尝试使用CSS表,但这不适用于100%的高度.你可以在这看到我的努力:

display: table

http://codepen.io/pju/pen/ZOmdEb

而对于flexBox,它有自己的问题.

display: flex

http://codepen.io/pju/pen/QEJXNZ

解决方法

我知道使用< video>用于除呈现视频之外的目的的元素是非常无意义的,但奇怪的是,元素的属性海报使其能够比< img>更好地处理图像.您不清楚实际包装器的尺寸与它的环境(即主体,视口或其他包装器?)的关系.

html,body {
  width: 100%;
  height: 100%;
  position: relative;
  Box-sizing: border-Box;
  background: #000;
}
*,*:before,*:after {
  Box-sizing: inherit;
  margin: 0;
  padding: 0;
}
.Box {
  display: table;
}
.frame {
  width: -moz-max-content;
  width: -webkit-max-content;
  width: max-content;
  height: auto;
  overflow: hidden;
  display: table-row;
}
.image {
  height: auto;
  width: 100%;
}
.title {
  font-size: 1.3em;
  font-family: 'Raleway';
  font-variant: small-caps;
  line-height: 1.15;
  text-align: center;
  background: rgba(221,126,110,.2);
  color: #EFEFEF;
}
<link href='https://fonts.googleapis.com/css?family=Raleway' rel='stylesheet'>
<section>
  <figure>
    <videoposter='https://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png'></video>
    <figcaption>Lena Söderberg 1972</figcaption>
  </figure>
</section>

html – Safari iOS不支持使用srcset / sizes的响应式图像

html – Safari iOS不支持使用srcset / sizes的响应式图像

我有以下内容

<img
            src="/img/footer/logo_white.png?v=2.0"
            srcset="/img/footer/logo_white.png?v=2.0 1x,/img/footer/logo_white2x.png?v=2.0 2x"
        >

这在普通和hidpi屏幕上工作正常.

但是当视口非常小(低于400px)时,徽标不适合,因此我需要在实际长度方面使用较小版本的图像,这是我创建的.然后我试了一下

<imghttps://www.jb51.cc/tag/logo/" target="_blank">logo"
                sizes="(max-width: 390px) 110px,175px"
                src="/img/footer/biw_logo.png?v=2.0"
                srcset="/img/footer/biw_logo_small.png?v=2.0 110w,/img/footer/biw_logo.png?v=2.0 175w,/img/footer/biw_logo2x.png?v=2.0 350w"
            >

这适用于显示低于390像素的视口的_small图像 – 但现在我已经失去了“高分辨率”因素;我不能强迫iphone5s中的iOS浏览器使用上述语法显示长度为110px的220px图像.

你能纠正我的语法吗?

<imghttps://www.jb51.cc/tag/logo/" target="_blank">logo" sizes="(max-width: 390px) 110px,175px" src="http://placehold.it/175x75" srcset="http://placehold.it/110x50 110w,http://placehold.it/175x75 175w,http://placehold.it/350x150 350w">

解决方法

你可以使用srcset和sizes来做到这一点.首先告诉浏览器您可以使用哪些图像以及这些图像有多少像素宽,这可以通过srcset完成:

<img srcset="
    /img/footer/logo_white.png?v=2.0 300w,/img/footer/logo_white2x.png?v=2.0 600w,/img/footer/logo_white_small.png?v=2.0 150w
">

现在浏览器知道它可以从三个150,300和600像素宽的图像中进行选择(我猜测尺寸,你的实际宽度可能会有所不同).

其次,您告诉浏览器图像在网页中显示的大小,这可以通过以下尺寸实现:

<img
    sizes="(max-width: 400px) 150px,300px"
    srcset="..."
>

浏览器现在知道,如果视口的宽度为400px或更小,则图像将显示为150px宽,对于大于400px的视口,它将显示为300px宽.

这足以让浏览器选择正确的图像.在具有普通屏幕的普通桌面上,它将选择300w图像,在hidpi桌面上,它将是600w图像.在具有正常屏幕的小视口上,150w将被选中并且在具有300w的hidpi的小视口上.

如果您想了解有关srcset和尺寸的更多信息,请查看http://ericportis.com/posts/2014/srcset-sizes/.

关于如何将 html 表与图像 src 一起下载为 csvhtml表格中怎么导入图片的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于Android HTML.fromHTML()与图像?、html css 如何将表头固定_html/css_WEB-ITnose、html – CSS图像和标题 – 高度100%在一起、html – Safari iOS不支持使用srcset / sizes的响应式图像的相关信息,请在本站寻找。

本文标签:

上一篇CSS:有没有办法让悬停元素只在点击后激活?(css 悬停)

下一篇Express 子路由(嵌套)默认参数(子路由vue)