整合營銷服務商

          電腦端+手機端+微信端=數據同步管理

          免費咨詢熱線:

          Excel文件打不開怎么辦?

          Excel文件打不開怎么辦?

          xcel打不開現象一:某個Excel表格文件打不開了,Excel主程序可以打開。

          • 軟件版本:
          • 軟件大小:
          • 軟件授權:
          • 適用平臺:
          • http://dl.pconline.com.cn/download/356399.html

          解決方法:Excel 2003 設置:打開Excel,選擇 工具--選項--常規 中把 “忽略其他應用程序”去掉勾就可以了。

          Excel 2007 中的設置:選擇Excel選項-->;高級-->;常規-->;“忽略使用動態數據交換(DDE)的其他應用程序”勾去掉。

          Excel打不開現象二:新建Excel文件保存以后可以正常打開,但是以前的Excel文件打不開了。

          解決方法:

          ①先打開Excel,然后單擊“文件”中的“打開”;

          ②在彈出的“打開”對話框中選擇打不開的Excel文件,然后點擊右下角“打開”旁邊的下拉箭頭,選擇“打開并修復”即可。

          數據分析中,將數據以表格的形式呈現出來是必不可少的環節,Pandas 是一個非常強大的數據分析庫,提供了很多方便的方法來處理和展示數據。今天,我們將學習如何使用 Pandas 自定義表格樣式并將其導出為 HTML 格式。

          通過這種方式,我們可以更好地組織和展示數據,并在網頁上共享我們的分析結果,并且,掌握Pandas數據存儲和表格樣式自定義的方式,在日常工作過程中有更多應用和實踐意義,將拓展我們的數據分析思路。

          導入數據

          首先,導入pandas庫,并為其設置別名pd,使用pandas的read_excel函數讀取指定路徑下的Excel文件,并將其內容存儲在DataFrame對象df中。

          import pandas as pd
          
          df=pd.read_excel(r'C:\Users\shangtianqiang\Desktop\2023年胡潤百富榜.xlsx')
          #默認顯示DataFrame的前五行。
          df.head()

          df.info()顯示DataFrame的簡要信息,包括索引、列名、數據類型和每列的非空值數量,這里顯示該數據表含有1241行數據。

          #數據預覽
          df.info()

          使用iloc方法篩選DataFrame的前100行數據。

          df=df.iloc[:100,:]#篩選前100行數據
          df

          自定義樣式

          定義一個樣式對象style,該對象用于生成HTML的樣式,這里對篩選出來的前100行的數據進行了樣式設置,它定義了一個居中的標題(h1標簽),一個表格(table標簽),以及表格中的表頭(th標簽)和單元格(td標簽)。

          • h1 標簽:文本居中,字體大小為24像素,下邊距為10像素;
          • table 標簽:邊框合并(border-collapse: collapse;),寬度為100%;
          • th, td 標簽:邊框為1像素的實線,內邊距為8像素,文本居中;
          • th 標簽:背景顏色為淺灰色(#f2f2f2)。
          # 定義CSS樣式,添加標題“2023年胡潤百富榜”  
          style="""  
          <style> 
          h1 {  
              text-align: center;  
              font-size: 24px;  
              margin-bottom: 10px;  
          }  
          table {  
              border-collapse: collapse;  
              width: 100%;  
          }  
          th, td {  
              border: 1px solid black;  
              padding: 8px;  
              text-align: center;  
          }  
          th {  
              background-color: #f2f2f2;  
          }  
          </style>  
          <head><title>2023年胡潤百富榜</title></head>
          <h1>2023年胡潤百富榜</h1> 
          """  

          將DataFrame轉換為HTML代碼,并添加樣式,index=False來去除行索引 。

          # 將DataFrame轉換為HTML代碼,并添加樣式  
          html=style + df.to_html(index=False)  # 使用index=False來避免顯示行索引 

          將生成的HTML內容寫入到名為'2023年胡潤百富榜.html'的文件中。

          # 將HTML代碼寫入文件或打印到控制臺  
          with open('2023年胡潤百富榜.html', 'w') as file:  
              file.write(html)  # 將HTML代碼寫入文件output.html

          完整版的代碼如下所示。

          import pandas as pd
          
          df=pd.read_excel(r'C:\Users\shangtianqiang\Desktop\2023年胡潤百富榜.xlsx')
          df=df.iloc[:100,:]#篩選前100行數據
            
          # 定義CSS樣式,添加標題“2023年胡潤百富榜”  
          style="""  
          <style> 
          h1 {  
              text-align: center;  
              font-size: 24px;  
              margin-bottom: 10px;  
          }  
          table {  
              border-collapse: collapse;  
              width: 100%;  
          }  
          th, td {  
              border: 1px solid black;  
              padding: 8px;  
              text-align: center;  
          }  
          th {  
              background-color: #f2f2f2;  
          }  
          </style>  
          <head><title>2023年胡潤百富榜</title></head>
          <h1>2023年胡潤百富榜</h1> 
          """  
            
          # 將DataFrame轉換為HTML代碼,并添加樣式  
          html=style + df.to_html(index=False)  # 使用index=False來避免顯示行索引  
            
          # 將HTML代碼寫入文件或打印到控制臺  
          with open('2023年胡潤百富榜.html', 'w') as file:  
              file.write(html)  # 將HTML代碼寫入文件output.html

          導出的HTML表格樣式如下所示,整體圖表風格較為簡潔。

          導入數據

          html的格式數據也是數據存儲的一種方式,使用read_html命令可以將其很便捷地導入,從而進行接下來的數據分析。

          import pandas as pd
          
          df_html=pd.read_html('2023年胡潤百富榜.html',encoding='gbk')[0]
          df_html

          通過學習如何使用 Pandas 自定義表格樣式并將其導出為 HTML 格式,我們掌握了更豐富的數據處理和展示技巧,并且,還可以根據實際業務需求來自定義表格樣式,實現與他人共享數據的目的。

          請耐心慢慢刷新到頁面完整顯示出來

          https://fjxasdf.github.io/daogou/

          原文章https://www.toutiao.com/i6711294610594857476/

          哪些優化?

          1.顯示商品圖片

          2.沒有顯示全部商品,只顯示熱門商品,避免數據、圖片加載太慢

          3.樣式稍微美化了

          4.上傳到GitHub,不過GitHub很卡,要刷新等好久才能看到

          python讀取excel生成json代碼

          import xlrd
          from datetime import date,datetime
          import json
          file='精選優質商品清單(內含優惠券).xls'
          def read_excel():
           wb=xlrd.open_workbook(filename=file)#打開文件
           # print(wb.sheet_names())#獲取所有表格名字
           sheet1=wb.sheet_by_index(0)#通過索引獲取表格
           # sheet2=wb.sheet_by_name('Page1')#通過名字獲取表格
           # print(sheet1)
           # print(sheet2)
           # print(sheet1.name) #表 名
           rows=sheet1.nrows #多少行
           # print(sheet1.ncols) #多少列
           # rows=sheet1.row_values(1)#獲取行內容
           category0=sheet1.col_values(4)#獲取列內容(類目)
           del category0[0]
           category=sorted(set(category0),key=category0.index) #類目列表->去重
           data=[]
           data_hot=[]
           # print(rows)
           # print(cols)
           for i,v in enumerate(category):
           category[i]=v.replace("/", "、")#吧"/"替換"、"
           data.append([category[i],[]])
           jsonData=json.dumps(category, ensure_ascii=False)
           with open('./daogou/category.json', 'w',encoding="utf-8") as f:
           f.write(jsonData)#保存分類json
           for i,v in enumerate(data):
           for x in range(rows):
           if v[0]==(sheet1.cell(x,4).value.replace("/", "、")):
           xo=sheet1.row_values(x)
           y=[xo[1],xo[2],xo[4],xo[6],xo[21]] #選擇保存商品名稱、圖片、鏈接等
           data[i][1].append(y)
           if x>0 and float(sheet1.row_values(x)[9]) >=1: #選擇傭金多的作為熱門
           xo=sheet1.row_values(x)
           y=[xo[1],xo[2],xo[4],xo[6],xo[21]]
           data_hot.append(y)
           data_hot=data_hot[:24]
           jsonData_hot=json.dumps(data_hot, ensure_ascii=False)
           with open('./daogou/results_hot.json', 'w',encoding="utf-8") as f:
           f.write(jsonData_hot)#保存熱門商品json
           for i,v in enumerate(data):
           jsonData=json.dumps(v[1], ensure_ascii=False)
           with open('./daogou/'+v[0]+'.json', 'w',encoding="utf-8") as f:
           f.write(jsonData)#保存每個分類商品json
           # jsonData1=json.dumps(data, ensure_ascii=False)
           # with open('results.json', 'w',encoding="utf-8") as f:
           # f.write(jsonData1)
           # print(sheet1.cell(0,0).value)#獲取表格里的內容,第一行第一個格內容
           # print(sheet1.cell_value(0,0))#獲取表格里的內容,第一行第一個格內容
           #print(sheet1.row(0)[0].value)#獲取表格里的內容,第一行第一個格內容
          if __name__=='__main__':
           	read_excel()
          

          創建html頁面,并引用json文件

          <!DOCTYPE html>
          <html lang="en">
          <head>
          	<meta charset="UTF-8">
          	<script src="../js/jquery.min.js"></script>
          	<link rel="stylesheet" href="../font/Alibaba-PuHuiTi-Regular.css">
          		<script>
          		var navo='';
          var info='';
          var data_total;//總數據
          function color16(){//十六進制顏色隨機
          	var r=Math.floor(Math.random()*256);
          	var g=Math.floor(Math.random()*256);
          	var b=Math.floor(Math.random()*256);
          	var color='#'+r.toString(16)+g.toString(16)+b.toString(16);
          	return color;
          }
          function nav_href(title,id){//錨跳轉
          		if ($('#'+title).length>0) {
          		location.href="#"+title;
          		}else{
          			var div_title="<div id='"+title+"' style='float:left;'>";
          			var div_content="<div class='pro_img' style='background:#ff5000'><b style='color:#FFF'>"+title+"</b><\/div>";
          			$('#load').show();
          			$.get('./'+title+'.json', function(data) {
          				$.each(data, function(index, val) {
          					div_content+="<a style='background:"+color16()+"' target='_blank' href='"+val[4]+"' class='pro_img'><img onload='$(this).show()' src="+val[1]+" style='width:100%;height:100%;display:none;' />"+val[0]+"<span class='money'>¥"+val[3]+"</span><span class='title'>"+val[0].substring(0,25)+"...</span><\/a>";
          					if ((index+1)==data.length) {
          						var div_footer="</div><br>";
          						infoo=div_title+div_content+div_footer;
          						$('#content').append(infoo);
          						location.href="#"+title;
          						$('#load').hide();
          					}
          						 });
          			},'json');
          			
          						 
          			
          		}
          		
          	
          }
          function get_data(){
          	$.get('./category.json', function(data) {//導航
          				$.each(data, function(index, val) {
          					 // console.log(val[0]);
          					 navo+="<a class='nav' href=javascript:;nav_href(\'"+val+"\',"+index+")>"+val+"</a> ";
          				});
          	$('#nav').html(navo);
          	$.get('./results_hot.json', function(data) {//熱門商品
          					var div_title="<div id='熱門商品' style='float:left;'>";
          					 var div_content="<div class='pro_img' style='background:#ff5000'><b style='color:#FFF'>熱門商品</b></span><\/div>";
          		$.each(data, function(index, val) {
          					 // console.log(val);
          					 
          					 	 div_content+="<a style='background:"+color16()+"' target='_blank' href='"+val[4]+"' class='pro_img'><img onload='$(this).show()' src="+val[1]+" style='width:100%;height:100%;display:none;' />"+val[0]+"<span class='money'>¥"+val[3]+"</span><span class='title'>"+val[0].substring(0,25)+"...</span><\/a>"
          					 
          					 
          					 // if (index==3) {return false}
          				});
          		var div_footer="</div><br>";
          		info+=div_title+div_content+div_footer;
          	$('#content').html(info);
          	$('#load').hide(0);	
          	});
          			},'json');
          }
          	
          		
          	</script>
          	<style>
          	#body{
          		/*border: 1px solid #eee;*/
          		width: 1110px;
          		margin:0 auto;
          	}
          	a.nav{
          		text-decoration: none;
          		margin-right: 10px;
          		padding: 0 5px;
          		/*padding-bottom: 10px;*/
          		display: inline-block;
          		color: #000;
           font-weight: 700;
          	}
          	#nav{
          		display: inline-block;
          	}
          *,html,body{
          	font-family:"Alibaba-PuHuiTi-Regular";
          }
          		#content{
          			margin-top: 10px;
          			display: inline-block;
          		}
          		.money{
          	 width: 100%;
           /* padding: 0px 10px; */
           background: #ffffffcc;
           position: absolute;
           left: 0;
           bottom: 50px;
           height: 30px;
           line-height: 30px;
           color: #F40;
           font-weight: 700;
           /* border-radius: 0 8px 0 0; */
           text-align: left;
           font-size: 18px;
          		}
          				.title{
           width: 100%;
           font-weight: 700;
           /* padding: 0px 10px; */
           background: #ffffffcc;
           position: absolute;
           left: 0;
           bottom: 0;
           height: 50px;
           line-height: normal;
           color: #000;
           /* border-radius: 0 8px 0 0; */
           text-align: left;
           font-size: 15px;
          		}
          		.pro_img{
          			position: relative;
          			float: left;
          			width: 220px;
          			height: 220px;
          			line-height: 220px;
          			text-align: center;
          			border: 1px solid #eee;
          			cursor: pointer;
          			font-size: 30px;
          			/*white-space:normal; */
          			overflow:hidden; /*超過部分不顯示*/
                text-overflow:ellipsis; /*超過部分用點點表示*/
           /*     white-space:nowrap;/*不換行*/
          		}
          		.input1{
          			 width: 300px;
          			 height: 30px;
          			 border: 1px solid #888;
          				border-radius: 10px 0 0 10px;
          				outline-style: none ;
          	
          		}
          		.button1{
          			margin-left: -7px;
           width: 50px;
           height: 34px;
           border-radius:0 10px 10px 0 ;
           outline-style: none ;
          		}
          		#search1{
          			/*width: 350px;*/
          			/*margin:0 auto;*/
          		}
          		#load{
          			position: fixed;
          			width: 100%;
          			height: 100%;
          			top: 0;
          			left: 0;
          			background: #000000ad;
          			z-index: 999;
          			text-align: center;
          			vertical-align: middle;
          		}
          		#load>span{
           display: inline-block;
           vertical-align: middle;
           height: 100%;
          		}
          		.load{
          			display: inline-block;
          			vertical-align: middle;
          			font-size: 50px;
          			color: #FFF;
          		}
          	</style>
          </head>
          <body onload="get_data()">
          <!-- loading -->
          <div id="load">
          	<span ></span>
          	<div class="load">加載中...</div>
          </div>
          <div id="body">
          <h1>網站僅學習交流!!網站中的商品信息均來自于互聯網。</h1>
          <!-- 		<div id="search1">
          		<input type="text" class="input1">
          		<button class="button1">搜索</button><b> 網站僅學習交流!!網站僅學習交流!!網站僅學習交流!!網站僅學習交流!!網站僅學習交流!!</b>
          	</div> -->
          	<div id="nav"></div>
          	<div id="content"></div>
          </div>
          </body>
          </html>
          

          完成上傳json文件和html頁面到GitHub


          主站蜘蛛池模板: 中文字幕日本一区| 一区二区三区高清在线| 国产精品综合AV一区二区国产馆| 视频在线观看一区二区| 日韩好片一区二区在线看| 亚洲视频在线一区二区| 一区二区3区免费视频| 中文字幕精品一区二区| 在线观看国产一区亚洲bd| 国产精品一区二区不卡| 亚洲日本va午夜中文字幕一区| 国产福利电影一区二区三区| 国产一区二区免费视频| 合区精品久久久中文字幕一区| 欲色aV无码一区二区人妻| 中文字幕永久一区二区三区在线观看| 日韩人妻不卡一区二区三区| 美女啪啪一区二区三区| 久久亚洲AV午夜福利精品一区| 久久精品国产亚洲一区二区| 国产日韩一区二区三免费高清| 国产在线一区二区综合免费视频| 亚洲日本一区二区一本一道| 卡通动漫中文字幕第一区| 日韩人妻无码一区二区三区 | 日韩精品在线一区二区| 激情内射亚洲一区二区三区| 成人h动漫精品一区二区无码| 视频一区二区在线播放| 亚洲午夜福利AV一区二区无码| 亚洲一区中文字幕久久| 国产免费一区二区三区| 国产一区二区三区手机在线观看| 国产一区二区三区在线看片| 国产精品一区二区四区| 国产91一区二区在线播放不卡 | 免费无码VA一区二区三区| 精品一区二区三区四区在线播放| 亚洲国产精品一区二区三区在线观看| 成人丝袜激情一区二区| 国产精品免费大片一区二区|