Enjoy your life ~
2015년 5월 12일 화요일
C# string.format example. focus printing numeric.
//Hexacode
String.Format("{0:X}", Convert.ToInt32(letter));
String.Format("{0:0.00}", 123.4567); // "123.46"
String.Format("{0:0.00}", 123.4); // "123.40"
String.Format("{0:0.00}", 123.0); // "123.00"
String.Format("{0:0.##}", 123.4567); // "123.46"
String.Format("{0:0.##}", 123.4); // "123.4"
String.Format("{0:0.##}", 123.0); // "123"
String.Format("{0:00.0}", 123.4567); // "123.5"
String.Format("{0:00.0}", 23.4567); // "23.5"
String.Format("{0:00.0}", 3.4567); // "03.5"
String.Format("{0:00.0}", -3.4567); // "-03.5"
//thousand ,
String.Format("{0:0,0.0}", 12345.67); // "12,345.7"
String.Format("{0:0,0}", 12345.67); // "12,346"
//case by case 0
String.Format("{0:0.0}", 0.0); // "0.0"
String.Format("{0:0.#}", 0.0); // "0"
String.Format("{0:#.0}", 0.0); // ".0"
String.Format("{0:#.#}", 0.0); // ""
//text include blank
String.Format("{0,10:0.0}", 123.4567); // " 123.5"
String.Format("{0,-10:0.0}", 123.4567); // "123.5 "
String.Format("{0,10:0.0}", -123.4567); // " -123.5"
String.Format("{0,-10:0.0}", -123.4567); // "-123.5 "
//{0: 0<; 0>; 0==}
String.Format("{0:0.00;minus 0.00;zero}", 123.4567); // "123.46"
String.Format("{0:0.00;minus 0.00;zero}", -123.4567); // "minus 123.46"
String.Format("{0:0.00;minus 0.00;zero}", 0.0); // "zero"
String.Format("{0:my number is 0.0}", 12.3); // "my number is 12.3"
String.Format("{0:0aaa.bbb0}", 12.3); // "12aaa.bbb3"
String.Format("{0:X}", Convert.ToInt32(letter));
String.Format("{0:0.00}", 123.4567); // "123.46"
String.Format("{0:0.00}", 123.4); // "123.40"
String.Format("{0:0.00}", 123.0); // "123.00"
String.Format("{0:0.##}", 123.4567); // "123.46"
String.Format("{0:0.##}", 123.4); // "123.4"
String.Format("{0:0.##}", 123.0); // "123"
String.Format("{0:00.0}", 123.4567); // "123.5"
String.Format("{0:00.0}", 23.4567); // "23.5"
String.Format("{0:00.0}", 3.4567); // "03.5"
String.Format("{0:00.0}", -3.4567); // "-03.5"
//thousand ,
String.Format("{0:0,0.0}", 12345.67); // "12,345.7"
String.Format("{0:0,0}", 12345.67); // "12,346"
//case by case 0
String.Format("{0:0.0}", 0.0); // "0.0"
String.Format("{0:0.#}", 0.0); // "0"
String.Format("{0:#.0}", 0.0); // ".0"
String.Format("{0:#.#}", 0.0); // ""
//text include blank
String.Format("{0,10:0.0}", 123.4567); // " 123.5"
String.Format("{0,-10:0.0}", 123.4567); // "123.5 "
String.Format("{0,10:0.0}", -123.4567); // " -123.5"
String.Format("{0,-10:0.0}", -123.4567); // "-123.5 "
//{0: 0<; 0>; 0==}
String.Format("{0:0.00;minus 0.00;zero}", 123.4567); // "123.46"
String.Format("{0:0.00;minus 0.00;zero}", -123.4567); // "minus 123.46"
String.Format("{0:0.00;minus 0.00;zero}", 0.0); // "zero"
String.Format("{0:my number is 0.0}", 12.3); // "my number is 12.3"
String.Format("{0:0aaa.bbb0}", 12.3); // "12aaa.bbb3"
Example for excel document with using C#
1. Excel document creation
2. Cells of A1 ~ G1 merge
3. wrtie text "C# Excel Creation"
4. set bold font
5. draw the box line
IDE : Microsoft Visual Studio 2005
At first, include Excel Library.
full source
=================================================================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Runtime.InteropServices;
namespace ExcelExample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
//create Excel application
Excel.Application oXL = new Excel.Application();
//if set true, can see excel doc during creating
oXL.Visible = true;
//must option. if set ture, it is possible to break from user's action
oXL.Interactive = false;
Excel._Workbook oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
Excel._Worksheet oSheet = (Excel._Worksheet)oWB.ActiveSheet;
Excel.Range oRng = null;
//get cells
oRng = oSheet.get_Range("B2", "H2");
oRng.MergeCells = true;
//set text
oRng.Value2 = "C# Excel Creation";
oRng.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
oRng.Font.Bold = true;
oRng.Font.Color = -16776961;
//box line
oRng.Borders[Excel.XlBordersIndex.xlEdgeBottom].LineStyle = Excel.XlLineStyle.xlContinuous;
oRng.Borders[Excel.XlBordersIndex.xlEdgeLeft].LineStyle = Excel.XlLineStyle.xlContinuous;
oRng.Borders[Excel.XlBordersIndex.xlEdgeRight].LineStyle = Excel.XlLineStyle.xlContinuous;
oRng.Borders[Excel.XlBordersIndex.xlEdgeTop].LineStyle = Excel.XlLineStyle.xlContinuous;
oXL.Interactive = true;
//clear object
Marshal.ReleaseComObject(oXL);
Marshal.ReleaseComObject(oWB);
Marshal.ReleaseComObject(oSheet);
//excute GC
GC.Collect();
}
catch (Exception eExcep)
{
String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat(errorMessage, eExcep.Message);
errorMessage = String.Concat(errorMessage, " Line: ");
errorMessage = String.Concat(errorMessage, eExcep.Source);
MessageBox.Show(errorMessage.ToString());
}
}
}
}
2. Cells of A1 ~ G1 merge
3. wrtie text "C# Excel Creation"
4. set bold font
5. draw the box line
IDE : Microsoft Visual Studio 2005
At first, include Excel Library.
full source
=================================================================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Runtime.InteropServices;
namespace ExcelExample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
//create Excel application
Excel.Application oXL = new Excel.Application();
//if set true, can see excel doc during creating
oXL.Visible = true;
//must option. if set ture, it is possible to break from user's action
oXL.Interactive = false;
Excel._Workbook oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
Excel._Worksheet oSheet = (Excel._Worksheet)oWB.ActiveSheet;
Excel.Range oRng = null;
//get cells
oRng = oSheet.get_Range("B2", "H2");
oRng.MergeCells = true;
//set text
oRng.Value2 = "C# Excel Creation";
oRng.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
oRng.Font.Bold = true;
oRng.Font.Color = -16776961;
//box line
oRng.Borders[Excel.XlBordersIndex.xlEdgeBottom].LineStyle = Excel.XlLineStyle.xlContinuous;
oRng.Borders[Excel.XlBordersIndex.xlEdgeLeft].LineStyle = Excel.XlLineStyle.xlContinuous;
oRng.Borders[Excel.XlBordersIndex.xlEdgeRight].LineStyle = Excel.XlLineStyle.xlContinuous;
oRng.Borders[Excel.XlBordersIndex.xlEdgeTop].LineStyle = Excel.XlLineStyle.xlContinuous;
oXL.Interactive = true;
//clear object
Marshal.ReleaseComObject(oXL);
Marshal.ReleaseComObject(oWB);
Marshal.ReleaseComObject(oSheet);
//excute GC
GC.Collect();
}
catch (Exception eExcep)
{
String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat(errorMessage, eExcep.Message);
errorMessage = String.Concat(errorMessage, " Line: ");
errorMessage = String.Concat(errorMessage, eExcep.Source);
MessageBox.Show(errorMessage.ToString());
}
}
}
}
using json on php
PHP5.3 , JSON
Example.php
================================================================
<?
require_once('inc/connect.php'); // your connect information
//sample query
$query = "SELECT * FROM TABLE1 WHERE 1 ";
$result = mysqli_query($link,$query);
$result_array = array();
while( $row = mysqli_fetch_array( $result, MYSQLI_ASSOC ) ){
$result_array[] = $row;
};
// encode to json
$result_array = json_encode( $result_array );
// print result
echo $_GET['callback'] . '(' .$result_array. ')';
mysqli_free_result($result);
mysqli_close($link);
?>
Example.php
================================================================
<?
require_once('inc/connect.php'); // your connect information
//sample query
$query = "SELECT * FROM TABLE1 WHERE 1 ";
$result = mysqli_query($link,$query);
$result_array = array();
while( $row = mysqli_fetch_array( $result, MYSQLI_ASSOC ) ){
$result_array[] = $row;
};
// encode to json
$result_array = json_encode( $result_array );
// print result
echo $_GET['callback'] . '(' .$result_array. ')';
mysqli_free_result($result);
mysqli_close($link);
?>
피드 구독하기:
글 (Atom)