Skip to content

Instantly share code, notes, and snippets.

@Pie001
Pie001 / cookieControl.js
Last active August 29, 2015 14:04
Cookie Control
// クッキーを設定
function setCookie(c_name, c_value) {
var today = new Date();
var cookieName = c_name;
var cookieValue = c_value;
today.setDate(today.getDate() + 365);
document.cookie = cookieName + "=" + escape(cookieValue) + "; path=/; expires=" + today.toGMTString() + ";";
}
// クッキーを削除
@Pie001
Pie001 / DeleteHtmlScriptTag.js
Last active August 29, 2015 14:04
Delete html script tag from text
// スクリプトタグ削除(タグのみ削除、空白は削除しない)
function TagDelete(Text) {
if (Text == "" || Text == null)
return "";
//スクリプト文字
Text = Text.replace(/</g, "&lt;");//"<"をコードに変換(タグ無効化)
Text = Text.replace(/>/g, "&gt;"); //">"をコードに変換(タグ無効化)
Text = Text.replace(/(<([^>]+)>)/ig, "");
@Pie001
Pie001 / GetLapsedTime.js
Last active December 21, 2016 05:51
timestampより経過時間を取得(JavaScript)
// timestampより経過時間を取得
function GetLapsedTime(timestamp) {
if (timestamp == "" || timestamp == null || timestamp == "0") {
return "";
}
//timestampをdateに変換
var d = new Date(timestamp * 1000);
var year = d.getFullYear();
var month = d.getMonth() + 1;
var day = d.getDate();
@Pie001
Pie001 / GetStringByByte.js
Last active December 21, 2016 05:48
指定した長さで文字列を切る
//指定した長さで文字列を切る
function GetStringByByte(str, num) {
len = 0;
estr = escape(str);
ostr = "";
for (i = 0; i < estr.length; i++) {
len++;
ostr = ostr + estr.charAt(i);
if (estr.charAt(i) == "%") {
i++;
@Pie001
Pie001 / XmlSample.xml
Last active August 29, 2015 14:04
XML Parse
<item>
<content>
<title>title1</title>
<desc>desc2</desc>
<flag>1</flag>
</content>
<content>
<title>title2</title>
<desc>desc2</desc>
<flag>2</flag>
@Pie001
Pie001 / GetLapsedTimeFromDateTime.cs
Last active December 21, 2016 05:49
DateTimeもしくはtimestampより経過時間を取得
// DateTimeより経過時間を取得
public static string GetLapsedTimeFromDateTime(DateTime dt)
{
string timeString = string.Empty;
TimeSpan ts = DateTime.Now.Subtract(dt);
int DayPeriod = Math.Abs(ts.Days);
if (DayPeriod < 1)
@Pie001
Pie001 / EPPLUS new Excel with Template
Last active December 21, 2016 12:23
EPPLUS テンプレートでエクセルファイル作成(Stream)
using System.IO;
using OfficeOpenXml;
// テンプレートファイルを元にDBから取得した値を指定したセルに設定したい場合、且つbyte[]をエクセルでファイルダウンロードさせる場合
byte[] source;
MemoryStream stream = new MemoryStream();
using (var template = System.IO.File.OpenRead(AppDomain.CurrentDomain.BaseDirectory + "/App_Data/template.xlsx"))
using (var package = new ExcelPackage(stream, template))
{
ExcelWorksheet worksheet = null;
@Pie001
Pie001 / DriveSettings.cs
Created December 21, 2016 01:16
特定ユーザでネットワーク接続
using System.Configuration;
using System.Runtime.InteropServices;
namespace Publisher.Network
{
public class DriveSettings
{
private enum ResourceScope
{
RESOURCE_CONNECTED = 1,
@Pie001
Pie001 / EPPLUS Make ExcelFile Sample
Last active June 25, 2021 00:47
EPPLUS エクセルファイル作成サンプル
using OfficeOpenXml;
using OfficeOpenXml.Style;
/// <summary>
/// Modelデータを元にExcel作成
/// </summary>
/// <param name="excelModel"></param>
/// <returns>byte[]</returns>
public byte[] MakeDetailsAsExcel(ContractExcelModel excelModel)
{
@Pie001
Pie001 / iTextSharp Make Pdf
Last active February 9, 2017 09:45
iTextSharp PDF作成サンプル
using iTextSharp.text;
using iTextSharp.text.pdf;
/// <summary>
/// PDFファイルを作成
/// ※1、フォーマット用のPDFファイルがある場合
/// ※2、複数枚のPDFを連続に出力する場合も対応可能
/// ※3、ウェブ・バッチ両方から呼ばれる場合を想定(共通ロジック)
/// </summary>
/// <param name="pdfStream">PDFストリーム</param>