Skip to content

A VBA macro to convert Excel selections into minimal, clean HTML, perfect for AI data analysis.

Notifications You must be signed in to change notification settings

Druadach/Excel-to-Minimal-HTML

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Excel to Clean HTML Converter for AI Analysis

A powerful VBA macro for Microsoft Excel that transforms a selected cell range into a clean, minimalist HTML table. It is specifically designed to prepare complex data structures for analysis by AI models.

The Problem: "Dirty" HTML and Wasted AI Tokens

When you use Excel's built-in "Save as Web Page" feature, it generates cluttered HTML filled with excessive styling, metadata, and Microsoft-specific tags. This "bloated" code is difficult for AI models to parse efficiently and can lead to inaccurate data interpretation.

Furthermore, this unnecessary code wastes valuable tokens. AI models process information in these small units of data, and more tokens mean higher processing costs and slower analysis.

The Solution: Clean, AI-Optimized HTML

This macro solves the problem by stripping away all non-essential formatting and attributes. It preserves only the core structure of the table (<table>, <tr>, <td>) and essential structural attributes (rowspan, colspan).

The result is a pure HTML representation of your data, optimized for clarity, machine readability, and cost-effective AI analysis.

Key Features

  • Minimalist Output: Removes all styling, comments, and non-essential metadata.
  • Structure Preservation: Retains rowspan and colspan attributes to maintain complex table layouts.
  • Whitespace Cleaning: Normalizes all spacing for a compact and clean output.
  • Clipboard Ready: The final HTML code is automatically copied to your clipboard for immediate use.

How to Use

  1. Open the VBA Editor: In Excel, press Alt + F11.

  2. Insert a New Module: In the VBA editor, go to Insert > Module.

  3. Paste the Code: Copy the code from the CopySelectionAsCleanHTML.vba file in this repository and paste it into the new module.

  4. Run the Macro:

    • Return to your Excel sheet and select the range of cells you want to convert.
    • Press Alt + F8 to open the Macro dialog.
    • Select CopySelectionAsCleanHTML and click Run.
  5. Paste Your Clean HTML: The clean HTML code is now on your clipboard, ready to be pasted into an AI prompt or any other application.

Example

The Source Excel Table:

1 1
1 1

Before: A complex Excel table with redundant code.

<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 15">
<link rel=File-List href="temp_excel_20251107162500_files/filelist.xml">
<style id="Book3_2851_Styles">
<!--table
	{mso-displayed-decimal-separator:"\.";
	mso-displayed-thousand-separator:"\,";}
.xl152851
	{padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:black;
	font-size:11.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:微软雅黑, sans-serif;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	mso-background-source:auto;
	mso-pattern:auto;
	white-space:nowrap;}
ruby
	{ruby-align:left;}
rt
	{color:windowtext;
	font-size:9.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:微软雅黑, sans-serif;
	mso-font-charset:134;
	mso-char-type:none;}
-->
</style>
</head>

<body>
<!--[if !excel]>  <![endif]-->
<!--The following information was generated by Microsoft Excel's Publish as Web
Page wizard.-->
<!--If the same item is republished from Excel, all information between the DIV
tags will be replaced.-->
<!----------------------------->
<!--START OF OUTPUT FROM EXCEL PUBLISH AS WEB PAGE WIZARD -->
<!----------------------------->

<div id="Book3_2851" align=center x:publishsource="Excel">

<table border=0 cellpadding=0 cellspacing=0 width=152 style='border-collapse:
 collapse;table-layout:fixed;width:114pt'>
 <col width=76 span=2 style='width:57pt'>
 <tr height=20 style='height:15.0pt'>
  <td height=20 class=xl152851 align=right width=76 style='height:15.0pt;
  width:57pt'>1</td>
  <td class=xl152851 align=right width=76 style='width:57pt'>1</td>
 </tr>
 <tr height=20 style='height:15.0pt'>
  <td height=20 class=xl152851 align=right style='height:15.0pt'>1</td>
  <td class=xl152851 align=right>1</td>
 </tr>
 <![if supportMisalignedColumns]>
 <tr height=0 style='display:none'>
  <td width=76 style='width:57pt'></td>
  <td width=76 style='width:57pt'></td>
 </tr>
 <![endif]>
</table>

</div>


<!----------------------------->
<!--END OF OUTPUT FROM EXCEL PUBLISH AS WEB PAGE WIZARD-->
<!----------------------------->
</body>

</html>

After: A clean HTML structure, ready for AI.

<html><body><div><table><col><tr><td>1</td><td>1</td></tr><tr><td>1</td><td>1</td></tr></table></div></body></html>

License

This project is licensed under the MIT License.

About

A VBA macro to convert Excel selections into minimal, clean HTML, perfect for AI data analysis.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages