Espace de nom de départ : Html2Ods

This commit is contained in:
Vincent Calame 2022-07-27 17:04:18 +02:00
parent 1716825d9f
commit d8eb327bab
5 changed files with 61 additions and 16 deletions

View File

@ -19,7 +19,7 @@ td {
}
.grandecellule {
font-size: 1.4rem;
font-size: 1.4rem;
}
@ -29,7 +29,6 @@ td {
cell.Header {
font-style: italic;
background-color: #2244aa;
}
cell.Grande ~ .essai {
@ -40,10 +39,25 @@ cell.Grande ~ .essai {
cell.EncorePlusGrande ~ .grandecellule {
font-size: 18pt;
background-color: #ddd;
}
cell.Heritage + cell.Bold {
padding: 0.3cm;
border: 0.75pt solid #333;
}
column.Longue ~ .longuecolonne {
width: 7cm;
width: 12cm;
}
column.Moyenne ~ .moyennecolonne {
width: 8cm;
}
column.Courte {
width: 4cm;
}
row.Entete {

View File

@ -14,12 +14,13 @@
<script type="text/javascript" src="../src/js/opendocument/OpenDocument.Style.js"></script>
<script type="text/javascript" src="../src/js/opendocument/OpenDocument.StyleManager.js"></script>
<script type="text/javascript" src="../src/js/opendocument/OpenDocument.OdsConverter.js"></script>
<script type="text/javascript" src="../src/js/Html2Ods.js"></script>
<script>
function fodsLink() {
let link = document.getElementById("link");
link.href = URL.createObjectURL(
OpenDocument.OdsConverter.convertToBlob("table")
Html2Ods.blob("table")
);
setTimeout(function () {
URL.revokeObjectURL(link.href);
@ -28,7 +29,7 @@ function fodsLink() {
}
function fodsContent() {
document.getElementById("text").innerText = OpenDocument.OdsConverter.convertToXml("table");
document.getElementById("text").innerText = Html2Ods.xml("table");
}
</script>
</head>
@ -44,9 +45,9 @@ function fodsContent() {
data-od-fixed-columns="1">
<col data-od-style="Longue">
<colgroup>
<col>
<col data-od-style="Courte">
</colgroup>
<colgroup span="2" class="longuecolonne">
<colgroup span="2" class="moyennecolonne">
</colgroup>
<thead>
<tr data-od-style="Entete">
@ -70,18 +71,17 @@ function fodsContent() {
<div data-od-hidden="true">
Caché dans OD
</div> Test à des lignes vides </td>
<td>Cellule 1.4</td>
<td data-od-style="Heritage">Cellule 1.4</td>
</tr>
<tr>
<td colspan="2" data-od-style="EncorePlusGrande">Cellule 2.1 (Très grande)</td>
<td data-od-style="EncorePlusGrande">Cellule 2.1 (Très grande)</td>
<!--<td>Cellule 2.2</td>-->
<td data-od-style="Bold">Cellule 2.3</td>
<td data-od-type="number" class="grandecellule">-160</td>
</tr>
<tr>
<td>Cellule 3.1</td>
<td>Cellule 3.2</td>
<td data-od-type="currency" data-text="1000">1000 €</td>
<td colspan="2">Cellule 3.1</td>
<td data-od-type="currency" data-od-text="1250">1100 €</td>
<td data-od-type="currency" data-od-currency="USD" data-text="-1315" class="essai">-$2500</td>
</tr>
</tbody>

12
src/js/Html2Ods.js Normal file
View File

@ -0,0 +1,12 @@
/* global OpenDocument */
var Html2Ods = {};
Html2Ods.blob = function (table, options) {
return OpenDocument.OdsConverter.convertToBlob(table, options);
};
Html2Ods.xml = function (table, options) {
return OpenDocument.OdsConverter.convertToXml(table, options);
};

View File

@ -123,7 +123,11 @@ OpenDocument.OdsConverter.prototype.convert = function (table, options) {
}
function _getCellText(cellElement) {
let cellText = cellElement.dataset[textDataAttribute];
let cellText = cellElement.dataset["odText"];
if (cellText) {
return cellText;
}
cellText = cellElement.dataset[textDataAttribute];
if (cellText) {
return cellText;
}
@ -281,7 +285,7 @@ OpenDocument.OdsConverter.readTableColumns = function(table, styleManager) {
let columnName = OpenDocument.COLUMNSTYLE_PREFIX + columnNumber;
columnNumber++;
let columnStyle = new OpenDocument.Style("column", columnName);
let originalStyleName = col.dataset["odStyle"];
let originalStyleName = _getColumnStyleName(col);
if (originalStyleName) {
let originalStyle = styleManager.getStyle("column-named", originalStyleName);
if (originalStyle) {
@ -296,6 +300,20 @@ OpenDocument.OdsConverter.readTableColumns = function(table, styleManager) {
result.push(new OpenDocument.Elements.TableColumn(columnName, col.span, "Standard"));
}
return result;
function _getColumnStyleName(col) {
let styleName = col.dataset["odStyle"];;
if (styleName) {
return styleName;
}
styleName = styleManager.getMatchingStyleName("column", col);
if (styleName) {
return styleName;
}
return "";
}
};

View File

@ -302,10 +302,11 @@ OpenDocument.StyleManager.readStyleSheet = function (styleManager, styleSheet) {
}
function _parseClass(classToken) {
if (!classToken.startsWith('.')) {
let dotIndex = classToken.indexOf('.');
if (dotIndex === -1) {
return false;
}
return classToken.substring(1);
return classToken.substring(dotIndex + 1);
}
};