public static void Main(string[] args) { //ExStart:1 // The path to the documents directory. string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Create directory if it is not already present. bool IsExists = System.IO.Directory.Exists(dataDir); if (!IsExists) { System.IO.Directory.CreateDirectory(dataDir); } //Instantiating a Workbook object Workbook workbook = new Workbook(); //Obtaining the reference of the first (default) worksheet by passing its sheet index Worksheet worksheet = workbook.Worksheets[0]; //Accessing the "A1" cell from the worksheet Aspose.Cells.Cell cell = worksheet.Cells["A1"]; //Adding some value to the "A1" cell cell.PutValue("Visit Aspose!"); //Create a style object Style style = cell.GetStyle(); //Setting the line style of the top border style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thick; //Setting the color of the top border style.Borders[BorderType.TopBorder].Color = Color.Black; //Setting the line style of the bottom border style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thick; //Setting the color of the bottom border style.Borders[BorderType.BottomBorder].Color = Color.Black; //Setting the line style of the left border style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thick; //Setting the color of the left border style.Borders[BorderType.LeftBorder].Color = Color.Black; //Setting the line style of the right border style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thick; //Setting the color of the right border style.Borders[BorderType.RightBorder].Color = Color.Black; //Apply the border styles to the cell cell.SetStyle(style); //Saving the Excel file workbook.Save(dataDir + "book1.out.xls"); //ExEnd:1 }
public static void Main(string[] args) { //ExStart:1 // The path to the documents directory. string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Create directory if it is not already present. bool IsExists = System.IO.Directory.Exists(dataDir); if (!IsExists) System.IO.Directory.CreateDirectory(dataDir); //Instantiating a Workbook object Workbook workbook = new Workbook(); //Obtaining the reference of the worksheet Worksheet worksheet = workbook.Worksheets[0]; //Accessing the "A1" cell from the worksheet Aspose.Cells.Cell cell = worksheet.Cells["A1"]; //Adding some value to the "A1" cell cell.PutValue("Visit Aspose!"); //Setting the horizontal alignment of the text in the "A1" cell Style style = cell.GetStyle(); //Setting the text direction from right to left style.TextDirection = TextDirectionType.RightToLeft; cell.SetStyle(style); //Saving the Excel file workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003); //ExEnd:1 }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); // Create directory if it is not already present. bool IsExists = System.IO.Directory.Exists(dataDir); if (!IsExists) { System.IO.Directory.CreateDirectory(dataDir); } //Instantiating a Workbook object Workbook workbook = new Workbook(); //Obtaining the reference of the worksheet Worksheet worksheet = workbook.Worksheets[0]; //Accessing the "A1" cell from the worksheet Aspose.Cells.Cell cell = worksheet.Cells["A1"]; //Adding some value to the "A1" cell cell.PutValue("Visit Aspose!"); //Setting the horizontal alignment of the text in the "A1" cell Style style = cell.GetStyle(); style.HorizontalAlignment = TextAlignmentType.Center; cell.SetStyle(style); //Saving the Excel file workbook.Save(dataDir + "book1.xls", SaveFormat.Excel97To2003); }
public static void Main(string[] args) { //ExStart:1 // The path to the documents directory. string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Create directory if it is not already present. bool IsExists = System.IO.Directory.Exists(dataDir); if (!IsExists) { System.IO.Directory.CreateDirectory(dataDir); } //Instantiate a Workbook. Workbook workbook = new Workbook(); //Get cells collection in the first (default) worksheet. Cells cells = workbook.Worksheets[0].Cells; //Get the D3 cell. Aspose.Cells.Cell c = cells["D3"]; //Get the style of the cell. Style s = c.GetStyle(); //Set foreground color for the cell from the default theme Accent2 color. s.ForegroundThemeColor = new ThemeColor(ThemeColorType.Accent2, 0.5); //Set the pattern type. s.Pattern = BackgroundType.Solid; //Get the font for the style. Aspose.Cells.Font f = s.Font; //Set the theme color. f.ThemeColor = new ThemeColor(ThemeColorType.Accent4, 0.1); //Apply style. c.SetStyle(s); //Put a value. c.PutValue("Testing1"); //Save the excel file. workbook.Save(dataDir + "output.out.xlsx"); //ExEnd:1 }
//Quang Huy 2014-02-19 /// <summary> /// Tạo viền cho ô /// </summary> /// <param name="cell"></param> /// <param name="position"></param> /// <param name="color"></param> private bool SetCellBorder(Aspose.Cells.Cell cell, BorderPosition position = BorderPosition.Around, System.Drawing.Color?color = null) { try { System.Drawing.Color c = color ?? System.Drawing.Color.Black; Aspose.Cells.Style style = cell.GetStyle(); if (((int)position & (int)BorderPosition.Top) == (int)BorderPosition.Top) { style.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = Aspose.Cells.CellBorderType.Thin; style.Borders[Aspose.Cells.BorderType.TopBorder].Color = c; } if (((int)position & (int)BorderPosition.Right) == (int)BorderPosition.Right) { style.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = Aspose.Cells.CellBorderType.Thin; style.Borders[Aspose.Cells.BorderType.RightBorder].Color = c; } if (((int)position & (int)BorderPosition.Bottom) == (int)BorderPosition.Bottom) { style.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = Aspose.Cells.CellBorderType.Thin; style.Borders[Aspose.Cells.BorderType.BottomBorder].Color = c; } if (((int)position & (int)BorderPosition.Left) == (int)BorderPosition.Left) { style.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = Aspose.Cells.CellBorderType.Thin; style.Borders[Aspose.Cells.BorderType.LeftBorder].Color = c; } if (((int)position & (int)BorderPosition.DiagonalDown) == (int)BorderPosition.DiagonalDown) { style.Borders[Aspose.Cells.BorderType.DiagonalDown].LineStyle = Aspose.Cells.CellBorderType.Thin; style.Borders[Aspose.Cells.BorderType.DiagonalDown].Color = c; } if ((((int)position & (int)BorderPosition.DiagonalUp) == (int)BorderPosition.DiagonalUp) || (position == BorderPosition.Full)) { style.Borders[Aspose.Cells.BorderType.DiagonalUp].LineStyle = Aspose.Cells.CellBorderType.Thin; style.Borders[Aspose.Cells.BorderType.DiagonalUp].Color = c; } //Apply the border styles to the cell cell.SetStyle(style); return(true); } catch { } return(false); }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Create directory if it is not already present. bool IsExists = System.IO.Directory.Exists(dataDir); if (!IsExists) { System.IO.Directory.CreateDirectory(dataDir); } // Instantiating a Workbook object Workbook workbook = new Workbook(); // Clearing all the worksheets workbook.Worksheets.Clear(); // Adding a new worksheet to the Excel object int i = workbook.Worksheets.Add(); // Obtaining the reference of the newly added worksheet by passing its sheet index Worksheet worksheet = workbook.Worksheets[i]; // Accessing the "A1" cell from the worksheet Aspose.Cells.Cell cell = worksheet.Cells["A1"]; // Adding some value to the "A1" cell cell.PutValue("Visit Aspose!"); // Setting the horizontal alignment of the text in the "A1" cell Style style = cell.GetStyle(); // Setting the vertical alignment of the text in a cell style.VerticalAlignment = TextAlignmentType.Center; cell.SetStyle(style); // Saving the Excel file workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003); // ExEnd:1 }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Create directory if it is not already present. bool IsExists = System.IO.Directory.Exists(dataDir); if (!IsExists) { System.IO.Directory.CreateDirectory(dataDir); } // Instantiating a Workbook object Workbook workbook = new Workbook(); // Adding a new worksheet to the Excel object int i = workbook.Worksheets.Add(); // Obtaining the reference of the newly added worksheet by passing its sheet index Worksheet worksheet = workbook.Worksheets[i]; // Accessing the "A1" cell from the worksheet Aspose.Cells.Cell cell = worksheet.Cells["A1"]; // Adding some value to the "A1" cell cell.PutValue("Hello Aspose!"); // Obtaining the style of the cell Style style = cell.GetStyle(); // ExStart:SetSubscript // Setting subscript effect style.Font.IsSubscript = true; // ExEnd:SetSubscript // Applying the style to the cell cell.SetStyle(style); // Saving the Excel file workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003); // ExEnd:1 }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); // Create directory if it is not already present. bool IsExists = System.IO.Directory.Exists(dataDir); if (!IsExists) { System.IO.Directory.CreateDirectory(dataDir); } //Instantiating a Workbook object Workbook workbook = new Workbook(); //Adding a new worksheet to the Excel object int i = workbook.Worksheets.Add(); //Obtaining the reference of the newly added worksheet by passing its sheet index Worksheet worksheet = workbook.Worksheets[i]; //Accessing the "A1" cell from the worksheet Aspose.Cells.Cell cell = worksheet.Cells["A1"]; //Adding some value to the "A1" cell cell.PutValue("Hello Aspose!"); //Obtaining the style of the cell Style style = cell.GetStyle(); //Setting the font to be underlined style.Font.Underline = FontUnderlineType.Single; //Applying the style to the cell cell.SetStyle(style); //Saving the Excel file workbook.Save(dataDir + "book1.xls", SaveFormat.Excel97To2003); }
public static void XuatDuLieuRaExcel(int iRowPara, int iColumnPara, string strSubHeaderPara, System.Data.DataTable tblBangDuLieuPara, string strTemplateNamePara) { //Đường dẫn file template string strSourceFilePri = string.Format("{0}{1}{2}", System.Windows.Forms.Application.StartupPath, PATH_TEMPLATES, strTemplateNamePara); SaveFileDialog saveFileDialogPri = new SaveFileDialog(); saveFileDialogPri.Filter = "Excel files (*.xls)|*.xls|All files (*.*)|*.*"; saveFileDialogPri.FilterIndex = 1; if (saveFileDialogPri.ShowDialog() == DialogResult.OK) { FileStream streamTemp = new FileStream(strSourceFilePri, FileMode.Open); Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(); workbook.Open(streamTemp); workbook.Worksheets.Add(); Aspose.Cells.Worksheet worksheet = workbook.Worksheets[0]; //Set cell store subHeader Aspose.Cells.Cells cellHeader = worksheet.Cells; //cellHeader.Merge(2, 0, 1, tblBangDuLieuPara.Columns.Count); worksheet.Cells["A3"].PutValue(strSubHeaderPara); //worksheet.IsGridlinesVisible = false; worksheet.Cells.ImportDataTable(tblBangDuLieuPara, false, iRowPara, iColumnPara, tblBangDuLieuPara.Rows.Count, tblBangDuLieuPara.Columns.Count); //Formatting for cells store database for (int i = 0; i < tblBangDuLieuPara.Rows.Count; i++) { for (int j = 0; j < tblBangDuLieuPara.Columns.Count; j++) { Aspose.Cells.Cell cell = worksheet.Cells[iRowPara + i, j]; workbook.Styles.Add(); Aspose.Cells.Style style = cell.GetStyle(); style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; style.Borders[BorderType.BottomBorder].Color = Color.Silver; style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; style.Borders[BorderType.TopBorder].Color = Color.Silver; style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; style.Borders[BorderType.LeftBorder].Color = Color.Silver; style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; style.Borders[BorderType.RightBorder].Color = Color.Silver; cell.SetStyle(style); } } //worksheet.AutoFitColumns(); //Save excel file workbook.Save(saveFileDialogPri.FileName, FileFormatType.Default); MessageBox.Show(WorkingContext.LangManager.GetString("frmRestSheet_ExportExcel_Messa"), WorkingContext.LangManager.GetString("Message"), MessageBoxButtons.OK, MessageBoxIcon.Information); streamTemp.Close(); if (File.Exists(saveFileDialogPri.FileName)) { Process.Start(saveFileDialogPri.FileName); } } }