使用 html 样式在 excel 中右对齐

Align right in excel using html style

我正在使用 html 文件创建 excel 文件,一切正常,但文本对齐。我想将我的数据格式化为文本并将其右对齐(默认为左对齐)。 像这样:

<style type="text/css">
.textclass { font-weight: bold; mso-number-format:"\@"; text-align:"right"}
</style>

使用此解决方案,粗体字体和格式都很好,但文本仍然左对齐。 提前感谢您的帮助。

你打错了。只需使用:

<style type="text/css">
    .textclass { font-weight: bold; mso-number-format:"\@"; text-align: right}
</style>

没有引号。

在您清理浏览器缓存之前,您的更改可能不会反映出来:

Chrome

Mozilla

要达到预期结果,请使用以下选项

浮动:右

显示:块

问题似乎是 textclass 元素是一个内联元素,不允许 text-align:right