本文目錄一覽:
- 1、aspose.cells java合併excel
- 2、如何使用Aspose Words for Java插入條形圖
- 3、Aspose.word中製作圖表後怎麼控制y軸上字體大小
- 4、您好,我想用java代碼調用wps?
aspose.cells java合併excel
using System; using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Data;
using Aspose.Cells;
/// summary
///OutFileDao 的摘要說明
/// /summary
public class OutFileDao
{
public OutFileDao()
{
//
//TODO: 在此處添加構造函數邏輯
//
}
/// summary
/// 測試程序
/// /summary
public static void testOut()
{
DataTable dt = new DataTable();
dt.Columns.Add(“name”);
dt.Columns.Add(“sex”);
DataRow dr = dt.NewRow();
dr[“name”] = “名稱1”;
dr[“sex”] = “性別1”;
dt.Rows.Add(dr);
DataRow dr1 = dt.NewRow();
dr1[“name”] = “名稱2”;
dr1[“sex”] = “性別2”;
dt.Rows.Add(dr1);
OutFileToDisk(dt, “測試標題”, @”d:\測試.xls”);
}
/// summary
/// 導出數據到本地
/// /summary
/// param name=”dt”要導出的數據/param
/// param name=”tableName”表格標題/param
/// param name=”path”保存路徑/param
public static void OutFileToDisk(DataTable dt,string tableName,string path)
{
Workbook workbook = new Workbook(); //工作簿
Worksheet sheet = workbook.Worksheets[0]; //工作表
Cells cells = sheet.Cells;//單元格
//為標題設置樣式
Style styleTitle = workbook.Styles[workbook.Styles.Add()];//新增樣式
styleTitle.HorizontalAlignment = TextAlignmentType.Center;//文字居中
styleTitle.Font.Name = “宋體”;//文字字體
styleTitle.Font.Size = 18;//文字大小
styleTitle.Font.IsBold = true;//粗體
//樣式2
Style style2 = workbook.Styles[workbook.Styles.Add()];//新增樣式
style2.HorizontalAlignment = TextAlignmentType.Center;//文字居中
style2.Font.Name = “宋體”;//文字字體
style2.Font.Size = 14;//文字大小
style2.Font.IsBold = true;//粗體
style2.IsTextWrapped = true;//單元格內容自動換行
style2.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
style2.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
style2.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
style2.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
//樣式3
Style style3 = workbook.Styles[workbook.Styles.Add()];//新增樣式
style3.HorizontalAlignment = TextAlignmentType.Center;//文字居中
style3.Font.Name = “宋體”;//文字字體
style3.Font.Size = 12;//文字大小
style3.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
int Colnum = dt.Columns.Count;//表格列數
int Rownum=dt.Rows.Count;//表格行數
//生成行1 標題行
cells.Merge(0, 0, 1, Colnum);//合併單元格
cells[0, 0].PutValue(tableName);//填寫內容
cells[0, 0].SetStyle(styleTitle);
cells.SetRowHeight(0, 38);
//生成行2 列名行
for (int i = 0; i Colnum; i++)
{
cells[1, i].PutValue(dt.Columns[i].ColumnName);
cells[1, i].SetStyle(style2);
cells.SetRowHeight(1, 25);
}
//生成數據行
for (int i = 0; i Rownum; i++)
{
for (int k = 0; k Colnum; k++)
{
cells[2 + i, k].PutValue(dt.Rows[i][k].ToString());
cells[2 + i, k].SetStyle(style3);
}
cells.SetRowHeight(2+i, 24);
}
workbook.Save(path);
}
public MemoryStream OutFileToStream(DataTable dt, string tableName)
{
Workbook workbook = new Workbook(); //工作簿
Worksheet sheet = workbook.Worksheets[0]; //工作表
Cells cells = sheet.Cells;//單元格
//為標題設置樣式
Style styleTitle = workbook.Styles[workbook.Styles.Add()];//新增樣式
styleTitle.HorizontalAlignment = TextAlignmentType.Center;//文字居中
styleTitle.Font.Name = “宋體”;//文字字體
styleTitle.Font.Size = 18;//文字大小
styleTitle.Font.IsBold = true;//粗體
//樣式2
Style style2 = workbook.Styles[workbook.Styles.Add()];//新增樣式
style2.HorizontalAlignment = TextAlignmentType.Center;//文字居中
style2.Font.Name = “宋體”;//文字字體
style2.Font.Size = 14;//文字大小
style2.Font.IsBold = true;//粗體
style2.IsTextWrapped = true;//單元格內容自動換行
style2.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
style2.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
style2.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
style2.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
//樣式3
Style style3 = workbook.Styles[workbook.Styles.Add()];//新增樣式
style3.HorizontalAlignment = TextAlignmentType.Center;//文字居中
style3.Font.Name = “宋體”;//文字字體
style3.Font.Size = 12;//文字大小
style3.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
int Colnum = dt.Columns.Count;//表格列數
int Rownum = dt.Rows.Count;//表格行數
//生成行1 標題行
cells.Merge(0, 0, 1, Colnum);//合併單元格
cells[0, 0].PutValue(tableName);//填寫內容
cells[0, 0].SetStyle(styleTitle);
cells.SetRowHeight(0, 38);
//生成行2 列名行
for (int i = 0; i Colnum; i++)
{
cells[1, i].PutValue(dt.Columns[i].ColumnName);
cells[1, i].SetStyle(style2);
cells.SetRowHeight(1, 25);
}
//生成數據行
for (int i = 0; i Rownum; i++)
{
for (int k = 0; k Colnum; k++)
{
cells[2 + i, k].PutValue(dt.Rows[i][k].ToString());
cells[2 + i, k].SetStyle(style3);
}
cells.SetRowHeight(2 + i, 24);
}
MemoryStream ms = workbook.SaveToStream();
return ms;
}
}
如何使用Aspose Words for Java插入條形圖
可以通過Aspose.Cells for Java創建靜態條形圖,並選染成圖片,然後再通過Aspose.Words for Java添加到Word文檔中:
//Create a new Workbook.
Workbook workbook = new Workbook();
//Get the first worksheet.
Worksheet sheet = workbook.getWorksheets().get(0);
//Set the name of worksheet
sheet.setName(“Data”);
//Get the cells collection in the sheet.
Cells cells = workbook.getWorksheets().get(0).getCells();
//Put some values into a cells of the Data sheet.
cells.get(“A1”).setValue(“Region”);
cells.get(“A2”).setValue(“France”);
cells.get(“A3”).setValue(“Germany”);
cells.get(“A4”).setValue(“England”);
Aspose.word中製作圖表後怎麼控制y軸上字體大小
左右都有的坐標軸,左邊的是主坐標軸,右邊的是次坐標軸
這個需要你繪製的圖表中至少含有兩條數據,比如數量和佔比
然後選中一條數據,右鍵,設置數據系列格式,系列產生在,選次坐標軸即可
您好,我想用java代碼調用wps?
代碼方法如下,從流加載wps文件,轉為pdf格式
import com.spire.doc.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class WordToPDF {
public static void main(String[] args)throws IOException {
FileInputStream inputStream = new FileInputStream(new File(“test.wps”));
Document document = new Document();
document.loadFromStream(inputStream, FileFormat.Doc);
document.saveToFile(“WPStoPDF.pdf”,FileFormat.PDF);
}
}
在程序中需引入 spire.doc.jar。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/152859.html