W

로컬 텍스트 엑셀 파일 읽기/쓰기

· 2010-01-23 (토) 20:44:45 · 6914

익스플로우의 보안에 허용만 가능하면 자바스크립트 상에서도 읽기/쓰기가 가능하다.

 

우선 text파일 읽고 쓰는 예제이다.(C:\\book1.txt를 읽고 씀)

 

=====================================================================================================================

<html>
<head>
<title>file save/load</title>

 

<script type="text/javascript">

    var fso=new ActiveXObject("Scripting.FileSystemObject");
    var filename="C:\\book1.txt";
    function savefile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,2,true);
        f.Write(myarea.innerHTML);
        f.Close();
    }
   
    function loadfile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,1);
        r=f.ReadAll();
        f.Close();
        myarea.innerHTML=r;
    }
   
   
    //function window.onload() {
    //    loadfile(filename);
    //}
</script>


</head>
<body>
 <table>
  <tr>
   <td>
    <div id=myarea contenteditable=true style="width:320;height:240;border:solid 2 inset;overflow:scroll;background-color:silver;"></div>
    <br><input type=button value=load onclick=loadfile()><input type=button value=save onclick=savefile()>
   </td>
  </tr>
 </table>
</form>
</body>
</html>

 

======================================Excel 파일 열고 쓰기 =================================================

- 쓰기 -

<script type="text/javascript">

// Declare the variables
var Excel, Book;

// Create the Excel application object.
Excel = new ActiveXObject("Excel.Application");

// Make Excel visible.
Excel.Visible = true;

// Create a new work book.
Book = Excel.Workbooks.Add()

// Place some text in the first cell of the sheet.
Book.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";

// Save the sheet.
Book.SaveAs("C:\\book1.xls");

// Close Excel with the Quit method on the Application object.
Excel.Application.Quit();
</script>

 

- 열기 -

function StartExcel() {
var oExcel;

var oWBook;
oExcel = new ActiveXObject("Excel.Application");

oExcel.Visible = true;

oExcel.workbooks.open("C:/test.xls");

oExcel.Quit();

oExcel = null;
}

 

간단한 파일 읽기의 경우 상당히 유용할 수 있겠다..

 
[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,187건
+
제목 글쓴이 날짜 조회
07-07-16 조회 3,128
07-07-06 조회 3,020
07-07-06 조회 3,452
07-06-23 조회 3,278
07-06-16 조회 2,784
07-05-20 조회 4,301
07-05-09 조회 3,475
07-05-09 조회 6,118
07-05-04 조회 2,712
07-04-30 조회 9,845
07-04-27 조회 4,344
07-04-26 조회 3,463
07-04-25 조회 5,308
07-04-18 조회 7,804
07-04-13 조회 3,139
07-04-12 조회 6,648
07-04-12 조회 5,062
07-04-12 조회 3,380
07-04-11 조회 5,734
07-04-05 조회 6,376
07-03-24 조회 4,437
07-03-20 조회 3,756
07-03-18 조회 4,001
07-03-18 조회 4,745
07-03-17 조회 4,243
07-03-16 조회 4,146
07-03-15 조회 5,310
07-03-13 조회 5,413
07-03-13 조회 3,594
07-03-08 조회 4,513
07-03-08 조회 4,000
07-03-08 조회 3,309
07-03-08 조회 4,200
07-03-05 조회 4,454
07-03-04 조회 2,923
07-03-01 조회 5,956
07-02-28 조회 3,241
07-02-27 조회 4,423
07-02-26 조회 3,342
07-02-26 조회 3,050
07-02-23 조회 3,685
07-02-23 조회 3,647
07-02-22 조회 4,034
07-02-22 조회 3,852
07-02-19 조회 3,860
07-02-17 조회 4,881
07-02-14 조회 8,189
07-02-12 조회 3,955
07-02-10 조회 3,585
07-02-02 조회 3,824
07-01-31 조회 3,503
07-01-29 조회 3,363
07-01-25 조회 5,129
07-01-21 조회 3,276
07-01-19 조회 3,071
06-12-15 조회 4,082
06-12-15 조회 4,481
06-12-15 조회 2,969
06-12-15 조회 4,519
06-12-15 조회 3,406
06-12-15 조회 4,105
06-12-15 조회 3,064
06-12-15 조회 2,783
06-12-15 조회 4,643
06-12-15 조회 3,190
06-12-15 조회 3,294
06-12-07 조회 4,746
06-12-07 조회 4,027
06-12-04 조회 4,680
06-11-27 조회 3,718
06-11-21 조회 4,025
06-11-15 조회 3,459
06-11-04 조회 3,355
06-10-29 조회 4,006
06-10-13 조회 3,873
06-10-13 조회 4,234
06-10-13 조회 4,186
06-10-12 조회 5,384
06-10-12 조회 4,303
06-10-04 조회 3,795
06-10-02 조회 4,572
06-09-29 조회 3,058
06-09-26 조회 3,408
06-09-26 조회 3,668
06-09-26 조회 3,308
06-09-26 조회 3,458
06-09-26 조회 4,366
06-09-25 조회 4,664
06-09-22 조회 5,006
06-09-22 조회 3,572
06-09-21 조회 4,349
06-09-21 조회 4,352
06-09-21 조회 3,556
06-09-21 조회 5,206
06-09-21 조회 3,733
06-09-21 조회 3,466
06-09-20 조회 3,055
06-09-15 조회 3,174
06-09-13 조회 3,487
06-09-11 조회 3,294